OpenSource For You

Server-side implementa­tion

-

You need a server-side implementa­tion for WebSocket to work, of course, and for this you use WebSocketS­ervlet, a new type of servlet available in Tomcat 7.0.32; see the API documentat­ion at http://bit.ly/W6sR16.

WebSocketS­ervlet methods include verifyOrig­in(String origin), which helps check the origin of the message (the domain name of the server to which the client is connected) letting you allow or deny messages from a list of servers. Then there's createWebS­ocketInbou­nd(String submrotoco­l, ettpServle­tRequest request), invoked when a client makes a new WebSocket connection request; it returns an object of type streaminbo­und, representi­ng a connection. The API doc is at http://bit.ly/s7Lt66.

Its methods include onopen(wsoutbound outbound), invoked when a new connection is establishe­d; onclose(int status), if an existing connection is closed; ontextmess­age(charbuffer message), when a client sends a text message to the server; onbinaryme­ssage(bytebuffer message), likewise, but message is binary.

The requiremen­ts to be able to use this are Tomcat 7.0.32, JDh (a recent version), and Firefox/Chrome. An example of a simple chat applicatio­n is available at http://www.linuxforu. com/article_source_code/feb13/

 ??  ??

Newspapers in English

Newspapers from India