Websocket is a network protocol.

Traditional browser-based applications, such as web games, often need to communicate with the server, and it is inevitable to open multiple HTTP requests to actively query the latest information to the server, but for the update operation of the client has to initiate a new request, which brings a series of problems:

  1. The server must provide several different TCP connections for the same client, one for sending messages to the client and one for handling each message sent to the server
  2. The communication protocol itself causes high communication overhead. For example, each Http request from client to server carries header information
  3. For the client to test, the student on the client must maintain the mapping between outgoing and incoming connections

In order to solve the above problems, Websocket emerged. It mainly realizes two-way communication based on TCP connection, and leaks the original TCP to the browser as much as possible.

What is the relationship between Websocket and TCP and HTTP?

Websocket is a TCP based protocol independent of TCP. The relationship with HTTP is simply that the websocket handshake phase is treated by the HTTP server as an upgrade request

Socket and socket are two very different things

By default, websocket uses port 80 for general requests and 443 for transmission of the encryption layer

From tools.ietf.org/html/rfc645…