# The Java EE 7 Tutorial

# 18 Java API for WebSocket

This chapter describes the Java API for WebSocket (JSR 356), which provides support for creating WebSocket applications. WebSocket is an application protocol that provides full-duplex communications between two peers over the TCP protocol.

In the traditional request-response model used in HTTP, the client requests resources, and the server provides responses. The exchange is always initiated by the client; the server cannot send any data without the client requesting it first. This model worked well for the World Wide Web when clients made occasional requests for documents that changed infrequently, but the limitations of this approach are increasingly relevant as content changes quickly and users expect a more interactive experience on the Web. The WebSocket protocol addresses these limitations by providing a full-duplex communication channel between the client and the server. Combined with other client technologies, such as JavaScript and HTML5, WebSocket enables web applications to deliver a richer user experience.

The following topics are addressed here:

- Introduction to WebSocket

- Creating WebSocket Applications in the Java EE Platform

- Programmatic Endpoints

- Annotated Endpoints

- Sending and Receiving Messages

- Maintaining Client State

- Using Encoders and Decoders

- Path Parameters

- Handling Errors

- Specifying an Endpoint Configurator Class

- The dukeetf2 Example Application

- The websocketbot Example Application

- Further Information about WebSocket