Server-side implementation
You need a server-side implementation for WebSocket to work, of course, and for this you use WebSocketServlet, a new type of servlet available in Tomcat 7.0.32; see the API documentation at http://bit.ly/W6sR16.
WebSocketServlet methods include verifyOrigin(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 createWebSocketInbound(String submrotocol, ettpServletRequest request), invoked when a client makes a new WebSocket connection request; it returns an object of type streaminbound, representing a connection. The API doc is at http://bit.ly/s7Lt66.
Its methods include onopen(wsoutbound outbound), invoked when a new connection is established; onclose(int status), if an existing connection is closed; ontextmessage(charbuffer message), when a client sends a text message to the server; onbinarymessage(bytebuffer message), likewise, but message is binary.
The requirements to be able to use this are Tomcat 7.0.32, JDh (a recent version), and Firefox/Chrome. An example of a simple chat application is available at http://www.linuxforu. com/article_source_code/feb13/