The WebSocket protocol is an extension to the HTTP 1.1 protocol to enable two-way communication between a client and a server. It is an independent TCP-based protocol. The protocol has two parts - handshake and data transfer. HTTP servers interpret its handshake as an upgrade request. By default, the WebSocket protocol uses port 80 for regular WebSocket connections and port 443 for WebSocket connections tunneled over Transport Layer Security (TLS).
The protocol works in the following sequence:
The client sends an HTTP upgrade request to the server through Access Gateway to establish a communication channel between the client and the server. (WebSocket protocol handshake)
The server sends an HTTP 101 response to the requesting client through Access Gateway. When the client receives the response, the HTTP connection is upgraded to WebSocket.
Bidirectional data exchange happens between the server and the client over the WebSocket connection.
Either of the participant in the data exchange requests to terminate the WebSocket connection. One participant sends a Close request to the other participant and the connection is terminated.
WebSocket enables Access Gateway to accept an HTTP upgrade request from a client.
The following diagram illustrates the flow of messages among the client, Access Gateway, and the server in a WebSocket communication:
Figure 2-5 WebSocket Communication