users@grizzly.java.net

Re: websocket + gws

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Wed, 01 Feb 2012 15:49:06 +0100

Hi Rama,

in order to configure WebSockets support on GWS, you have to add
WebSockets async Filter:

/gws.addAsyncFilter(new com.sun.grizzly.websockets.WebSocketAsyncFilter());/

next step is to register your WebSocketApplication:

/com.sun.grizzly.websockets.WebSocketEngine.getEngine().register(new
CustomWebSocketApplication());/

where CustomWebSocketApplication extends
com.sun.grizzly.websockets.WebSocketApplication. For example echo
application may look like:

/class EchoWebSocketApplication extends WebSocketApplication {
     @Override
     public boolean isApplicationRequest(Request request) {
         return request.requestURI().equals("/echo");
     }

     public void onMessage(WebSocket socket, String data) {
         super.onMessage(socket, data);
         socket.send(data);
     }
}
/
first method (/isApplicationRequest/) decides if incoming websocket
connection is related to this application and another method
(/onMessage/) is implementing the actual processing logic.
There is useful method implemented in WebSocketApplication:
/Set<WebSocket> getWebSockets();/

which returns all the websockets connected to the application at the moment.

We're currently working on websockets section of user's guide, so If you
need more info - pls. ask.

Thanks.

WBR,
Alexey.

On 01/31/2012 05:53 PM, rama.rama_at_tiscali.it wrote:
> Hello,
>
>
> there is any guide / help / how to to add web socket in a
> grizzly web server (1.9.x) embedded application?
>
>
> something like
>
> gws
> = new GrizzlyWebserver(80,...)
> gws.addGrizzlyAdapter(...)
> gws.addAsync
> (...websocket?...)
>
> i want to do some test with web socket, some infos
> will be valuable as all what i have found was example for grizzly +
> glass fish not as a standalone embeddable server
>
> warm regards
>
>
>
>
> E' nata indoona: chiama, videochiama e messaggia Gratis. Scarica indoona per iPhone, Android e PC: http://www.indoona.com/