Last update:2022-03-17 10:08:11
WebSocket is a computer communication protocol which provides full-duplex communication channels over a single TCP connection. It mainly solves the problem that the client cannot obtain updated data from the server in time under the traditional HTTP communication, and establishes a two-way connection between the client and the server to enrich web application functionality based on event, improving timeliness and application performance.
WebSocket is especially useful under below scenarios when concurrency and real-time response requirements are high:
In the process of implementing WebSocket connection, the client first needs to initiate a WebSocket connection request, and then the server returns a response. This process is called “handshake”. After the handshake is successful, the client and the server establish a full-duplex communication channels to transfer data to each other.
The comparison between Traditional HTTP and WebSocket Interactions
When the connection is established, the client and the server will maintain persistent connection. Once the data is updated, the server will proactively push it to the client.