hfSic

hfSic

Comparison of TCP Long Connections and WebSocket

TCP Long Connection#

HTTP/1.1 defaults to a long connection (Connection defaults to Keep-alive), so as long as requests are maintained within a specified time (timeout) and the server's and client's capacity limits are not reached, it can be maintained for a long time.

Compared to short connections, it simply lacks the open and close operations between multiple requests.

WebSocket Long Connection#

WebSocket is a bidirectional transmission protocol based on the TCP protocol, established through the HTTP/1.1 protocol's 101 status code handshake.

After the WebSocket handshake is established via the HTTP protocol, subsequent communication occurs through the TCP protocol instead of the HTTP protocol.

Differences#

  • Since WebSocket is a full-duplex protocol, the server can actively send data to the client, while a TCP long connection needs to wait for the client to initiate a request to respond.
  • WebSocket establishes a connection first and then maintains communication, allowing subsequent communication to omit some state information, while a TCP long connection may need to carry state information with each request.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.