Red Hat Training

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

Chapter 3. WebSocket on Tomcat

3.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 JSR 356 API for creating WebSocket applications independent of the implementation. The WebSocket API is purely event driven.
Developers can use 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 WebSocket protocol that 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. While a WebSocket server is WebSocket endpoint which is already published and awaits connections from peers.
Some of the examples where WebSocket can be used are banking applications, chat applications, multiplayer applications, and social networking applications.