Grizzly 2.0: websockets support

We've added websockets (draft-hixie-thewebsocketprotocol-76) support into Grizzly 2.0, both client and server side and ported websockets-chat sample taken from Grizzly 1.9.19 (blog from Justin).

The API, common for client and server parts:

  • WebSocket, abstraction, which represents websocket unit
  • WebSocketEngine, which works as WebSocketApplication registry for server part and also contains base websockets handshake logic
  • WebSocketFilter, the key part of websocket implementation. It's Grizzly filter, which is responsible for handling websockets communication and and forward processing to correct websocket handlers.

The server-side API consists of

The client-side API:

Here are websockets chat sample sources, which includes:

To run the standalone websockets server please do following:

  • svn checkout https://www.dev.java.net/svn/grizzly/branches/2dot0/code/samples/websockets/chat
  • cd chat
  • mvn install
  • java -cp ./target/grizzly-websockets-chat-2.0.0-SNAPSHOT.jar com.sun.grizzly.samples.websockets.ChatWebSocketServer ./webapp

To run the standalone client (assume you have completed first 3 steps from the server side list)

  • java -cp ./target/grizzly-websockets-chat-2.0.0-SNAPSHOT.jar com.sun.grizzly.samples.websockets.ChatWebSocketClient

To run the application in browser, I used the latest dev version of Chromium, which implements the latest websockets draft and requested following URL: http://localhost:8080/index.html

So finally you're able to chat using standalone client and browser.

Comments:

Great news.

What build of GlassFish 3.1 includes this? I assume it will make it into M2?

- eduard/o

Posted by Eduardo Pelegri-Llopart on June 16, 2010 at 01:59 PM CEST #

Hi Eduardo,
GlassFish 3.1 M2 will definitely have websockets support. Though it would be provided by Grizzly 1.9.19, the actual API would be pretty similar to what I've described.

Posted by Alexey on June 17, 2010 at 03:59 AM CEST #

I try to develop a WebSocket server application and if the nightly build of Glassfish 3.1 will have Grizzly 1.9.19 and not 2dot0 then it make it hard (or imposible) since all changes will be done in 2dot0, are will it also be applied to 1.9.19?

Posted by Ido Ran on June 17, 2010 at 05:05 AM CEST #

Hi Eduardo,

Thank a lot for your share. I have seen the code of ChatWebSocketServer and I tell me if we could create an OSGi Bundle Activator which start the server (like the main Java).

I think it could be interesting to have grizzly-websockets in OSGi -env for instance start/stop some ChatApplication (you could imagine have a bundle/per ChatApplication (ChatApplication for a particular topic).

Tell me if you like this idea, I could help you to do that if you wish.

Regards Angelo

Posted by Angelo on August 24, 2010 at 11:11 AM CEST #

Hi

The article was really informative. I was able to setup the same. But what if my websocket can only connect to the glassfish via a proxy server from my machine. Does the current api supports that.

Regards
Achuth

Posted by Achuth on September 27, 2010 at 05:14 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

oleksiys

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today