Java WebSocket API Handbook
  • Introduction
  • Warm up
  • API Overview
  • Programming Model
  • Sending Messages
  • Receiving Messages
  • WebSocket Client API
  • Configuration
  • Deployment
  • Part-1: Tying in with the Java EE Platform
  • Part-2: Tying in with the Java EE Platform
  • Lifecycle and Concurrency semantics
Powered by GitBook
On this page
  • WebSocket primer
  • What
  • Why
  • WebSocket as a Java standard
  • The API (specification) and its implementations
  • Java EE Platform
  • Time to dive in

Was this helpful?

Warm up

PreviousIntroductionNextAPI Overview

Last updated 5 years ago

Was this helpful?

This chapter provides a gentle introduction to WebSocket in order to get you warmed up for things to come

WebSocket primer

What

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

Why

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)

WebSocket as a Java standard

The API (specification) and its implementations

Java EE Platform

Time to dive in

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.

IETF
RFC 6455
a W3C standard
HTTP Upgrade mechanism
JSR 356
specification
Tyrus
Undertow
Tomcat 7
Java Enterprise Edition 7
Java EE 7 compliant
Spring
Jetty