Chapter 7. WebSocket
The Java API for WebSocket is defined as JSR 356, and the complete specification can be downloaded.
Unlike HTTP, there is no need to create a new TCP connection and send a message chock-full of headers for every exchange between client and server. Once the initial handshake happens via HTTP Upgrade (defined in RFC 2616, section 14.42), the client and server can send messages to each other, independent of the other. There are no predefined message exchange patterns of request/response or one-way between client and server. These need to be explicitly defined over the basic protocol.
The communication between client and server is pretty symmetric, but there are two differences:
A client initiates a connection to a server that is listening for a WebSocket request.
A client connects to one server using a URI. A server may listen to requests from multiple clients on the same URI.
Other than these two differences, the client and server behave ...