Red Hat Training

A Red Hat training course is available for Red Hat JBoss Web Server

Chapter 4. WebSocket on Tomcat

4.1. About WebSocket

WebSocket is a web technology that provides bi-directional, full duplex, messages to be instantly distributed between the client and server over a single TCP socket connection. A full duplex communication allows two-way communication simultaneously.
The container provides an implementations of the WebSockets 1.0 JSR 356 API. To use the API, you must run Java 7+ and configure the APR or NIO2 HTTP/1.1 connectors of the web container.
JSR 356 is a standard for WebSocket API for Java. Developers can use the JSR 356 API for creating WebSocket applications independent of the implementation. The WebSocket API is purely event driven.
Developers can use the JSR 356 Java API for WebSocket to integrate WebSockets in applications on the server side as well as on the Java client side. Tomcat 7 and 8 implement the WebSocket protocol which adheres to JSR-356 standard.
A Java client uses JSR 356-compliant client implementation to connect to a WebSocket server. For web clients, WebSocket JavaScript API can be used to communicate with WebSocket server. The only difference between a WebSocket client and a WebSocket server is the method in which they are connected. A WebSocket client is a WebSocket point from which the connection to a peer originates. A WebSocket server is WebSocket endpoint which is already published and awaits connections from peers.
Some examples where WebSocket can be used include banking, chat, multiplayer, and social networking applications.