Warm up
Last updated
Was this helpful?
Last updated
Was this helpful?
This chapter provides a gentle introduction to WebSocket in order to get you warmed up for things to come
Simply put, WebSocket is an standard recognized by . To be specific, it's a protocol (just like HTTP) which works on top of TCP. You can think of it as a mid-way between long-polling and Server Sent Events (SSE - ). A WebSocket connection piggybacks on top of HTTP for the initial handshake ().
Important: Once established, the underlying TCP connection remains open
It's key characteristics are as follows
Bi-directional: both server and client can initiate a communication
Full duplex: once the WebSocket session is established, both server and client can communicate independent of each other
The aforementioned characteristics make WebSocket a great fit for applications which require have low latency and high frequency messaging requirements e.g. chat, monitoring, multiplayer online games, broadcasting real time finance data etc. Some of it's benefits (as compared to other solutions) include
Less verbosity (as compared to HTTP)
More efficient (as compared to long-polling)
Richer semantics (as compared to Server Sent Events)
That's it for the warm up! Let's forge ahead..
The Java equivalent for this technology is defined by - a standard API which was first released in May 2013 along with a 1.1 release (minor additions) in August 2014. Just like any other JSR (Java Specification Request) defined API, the Java API for WebSocket is backed by a which makes it possible to have multiple implementations of the same. Some of these are
, which is an open source project and also happens to be the Reference Implementation included in Weblogic and GlassFish
(included in JBoss EAP and Wildfly)
and above (it provides an internal implementation)
JSR 356 is also included as a part of the (Java EE 7) Platform. Any application server would include a pre-packaged (default) implementation of this API as well as integration with other Java EE technologies like EJB, CDI, Security etc.
JSR 356 support is also provided by other containers/frameworks such as , etc.