Jetty Logo
Version: 9.4.26.v20200117
Contact the core Jetty developers at

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

Chapter 26. WebSocket Introduction

Table of Contents

What Jetty provides
WebSocket APIs
Enabling WebSocket

WebSocket is a new protocol for bidirectional communications initiated via HTTP/1.1 upgrade and providing basic message framing, layered over TCP. It is based on a low-level framing protocol that delivers messages in either UTF-8 TEXT or BINARY format.

A single message in WebSocket can be of any size (the underlying framing however does have a single frame limit of 63-bits). There can be an unlimited number of messages sent. Messages are sent sequentially, the base protocol does not support interleaved messages.

A WebSocket connection goes through some basic state changes:

Table 26.1. WebSocket connection states



A HTTP Upgrade to WebSocket is in progress


The HTTP Upgrade succeeded and the socket is now open and ready to read / write


A WebSocket Close Handshake has been started


WebSocket is now closed, no more read/write possible

When a WebSocket is closed, a status code and short reason string is provided.

What Jetty provides

Jetty provides an implementation of the following standards and specs.


The WebSocket Protocol

We support the version 13 of the released and final spec.

Jetty tests its WebSocket protocol implementation using the autobahn testsuite.


The early drafts of WebSocket were supported in Jetty 7 and Jetty 8, but this support has been removed in Jetty 9. This means that Jetty 9 will not support the old browsers that implemented the early drafts of WebSocket. (such as Safari 5.0 or Opera 12)


Want to know if the browser you are targeting supports WebSocket? Use to find out.


The Java WebSocket API (javax.websocket)

This is the official Java API for working with WebSockets.

Unstable standards and specs:


Per Frame Compression Extension.

An early extension draft from the Google/Chromium team that would provide WebSocket frame compression. perframe-compression using deflate algorithm is present on many versions of Chrome/Chromium.

Jetty’s support for perframe-compression is based on the draft-04 spec. This standard is being replaced with permessage-compression.


Per Frame Compression Extension.

This is the replacement for perframe-compression, switching the compression to being based on the entire message, not the individual frames.

See an error or something missing? Contribute to this documentation at Github!(Generated: 2020-01-17)