Long and short connections and long and short polling

Long and short connections and long and short polling

1. What is the long and short connection?

Long and short connections do not refer to long and short HTTP connections, but TCP connections. Short connection : After the client initiates an HTTP request, the client will establish a TCP link with the server, and then send the HTTP request through the TCP link. In HTTP1.0, the client will close the TCP connection after getting the response. The next time the request is made The TCP link is re-established. Long connection : In order to save overhead and improve efficiency, long connection is implemented in HTTP 1.1, that is, multiple HTTP requests can be sent once a TCP link is established, and the connection is closed after knowing that no HTTP request has been sent for a long time.

In the HTTP1.1 version, connection:keep-alivelong connections can be realized by setting the request header and response header .

2. What is long and short polling

Short polling : The client will request the server to update the page content at regular intervals. If the server has data, it will return data, and if there is no data, it will return empty data.
Long polling : After the client initiates the request, the server receives the request. If there is data or update, it will return the data. If there is no data or update, the request will be suspended. The data will not be returned until there is data or update, but there is a certain amount of data. Time limit, timeout will also return (regardless of whether there is data).

Short polling has poor real-time performance, but it occupies less server resources.
Long polling has good real-time performance, but it occupies more server resources.

Guess you like

Origin blog.csdn.net/wdhxs/article/details/109818644