Java Reference
In-Depth Information
Java API for WebSocket 1.0
The Java API for WebSocket 1.0 was developed under JSR 356. This section just
gives you an overview of the API. The complete document specification (for more in-
formation) can be downloaded from
jsr356/index.html .
What is WebSocket?
Originally called TCPConnection in previous versions of the HTML5 specification,
WebSocket is an independent protocol built over the TCP ( Transmission Control
Protocol ), which enables bidirectional and full-duplex communication between a cli-
ent and a server.
To open a WebSocket connection in web application , the web client uses an HTTP
request to ask the server to upgrade the connection to a WebSocket connection. If
the server supports and accepts the WebSocket protocol connection request, it will
still return a response through HTTP. From that moment, the communication is es-
tablished and both parties can send and receive data by using only the WebSocket
Why WebSocket?
Today, many web applications (instant messaging, trading platforms, some e-com-
merce platforms, online gaming, and so on) require a real-time communication
between a client (browser) and a server. If you do not know, the HTTP protocol is a
a web page, the client must always open a connection to the server, send a request,
wait for the server response, and then close the connection. Thus, in a real-time con-
text, the client will frequently send requests to the server in order to detect the pres-
ence of new data and many request-responses will be made even when there is no
new information.
To get around this problem, many solutions have been proposed. The most efficient
was certainly long polling, which can be described like this: the client makes a request
to the server; if there is data available, the server responds. Otherwise, it waits until
there is new information before responding. After receiving the response, the cli-
Search WWH ::

Custom Search