# Warm up

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 [IETF](https://www.ietf.org/) standard recognized by [RFC 6455](https://tools.ietf.org/html/rfc6455). 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 W3C standard](https://www.w3.org/TR/eventsource/)). A WebSocket connection piggybacks on top of HTTP for the initial handshake ([HTTP Upgrade mechanism](https://svn.tools.ietf.org/svn/wg/httpbis/specs/rfc7230.html#header.upgrade)).

> **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&#x20;

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

The Java equivalent for this technology is defined by [**JSR 356**](https://jcp.org/en/jsr/detail?id=356) - 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 [specification](https://jcp.org/aboutJava/communityprocess/mrel/jsr356/index.html) which makes it possible to have multiple implementations of the same. Some of these are

* [Tyrus](https://tyrus.java.net/), which is an open source project and also happens to be the **Reference Implementation** included in Weblogic and GlassFish
* [Undertow](http://undertow.io/) (included in JBoss EAP and Wildfly)
* [Tomcat 7](http://tomcat.apache.org/tomcat-7.0-doc/index.html) and above (it provides an internal implementation)

### Java EE Platform

JSR 356 is also included as a part of the [**Java Enterprise Edition 7**](http://www.jcp.org/en/jsr/detail?id=342) (Java EE 7) Platform. Any [Java EE 7 compliant](http://www.oracle.com/technetwork/java/javaee/overview/compatibility-jsp-136984.html) 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 [Spring](https://projects.spring.io/spring-framework/), [Jetty](http://www.eclipse.org/jetty/) etc.

## Time to dive in

That's it for the warm up! Let's forge ahead..


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://abhishek-gupta.gitbook.io/java-websocket-api-handbook/introduction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
