You must have heard about the so-called long connections and short connections in HTTP. However, what is a long connection? What is a short connection? I think many people are confused and can't fully tell the difference between them. Today I will take you to fully understand them and you will never forget them again.
What is a long connection? The difference between HTTP long and short connections lies in whether the TCP long connection or short connection is used. In HTTP 1.0, short connections are used by default, but since HTTP 1.1, the default connections have all become long connections. The difference between long and short connections? Essentially, it is determined by TCP connections. Why do we say that? Because TCP is a two-way channel, it can remain open for a period of time, so there is a difference between long connections and short connections. For example: after the data transmission is completed, the TCP connection is maintained uninterrupted, and when waiting for the same domain name to request again, the TCP connection channel continues to be used for data transmission. This is a long connection. For example, if you need to email something to your friend, the HTTP protocol refers to the express delivery form you need to fill out. The action of filling out the express delivery form when sending the item is equivalent to making an HTTP request. And your express delivery needs to be delivered by means of transportation, which can be trucks, lorries, high-speed trains, airplanes, etc. The TCP protocol refers to the means of transportation for delivering express delivery. Because transportation is needed, there must be roads, such as roads or railways on the ground and air routes in the sky. Then this transportation road is the TCP connection, because this road is bidirectional and can be transported both in and out. Therefore, the TCP connection is also called a bidirectional data channel. If there are vehicles transporting goods on this road for a long time, it is called a long connection. If there are no vehicles passing by after a period of transportation, it is called a short connection. Therefore, we can see that the so-called HTTP connection refers to the TCP connection. A TCP connection that can be maintained for a period of time is a long connection, and a short connection that is automatically disconnected after a request is initiated is a short connection, so there is a long connection and a short connection. So the question is, what kind of connection can be called a long connection? Long connection conditions:
Now you are curious about keep-alive. What is the Connection setting keep-alive? Next, I will take you to unveil its mystery. What is Keep-alive? As we know, HTTP protocol uses the "request-response" mode. When the Connection is not in keep-alive mode, the server and client need to re-establish a connection for each request-response task. After the task is completed, the connection is disconnected. When the Connection is in keep-alive mode, the server and client will always maintain a connection. When a new request task occurs, there is no need to re-establish the connection. This saves time and does not consume resources. Non-keep-alive: As can be seen from the above figure: Steps for short connection: Steps for long connection: Next, let's talk about the scenarios in which long connections and short connections are used.
Because we mentioned above that HTTP connection is actually TCP connection, so here we have to talk in detail, what are the characteristics of TCP connection? TCP Connection When the network responds to a request, a connection must be established between the client and the server. When the network request is completed, both parties can release the connection when they no longer need it. The TCP connection is used here. The connection in the TCP protocol relies on the "three-way handshake" and the release relies on the "four-way handshake". Therefore, each connection consumes resources and time. 1. TCP's "three-way handshake": Schematic diagram of TCP's three-way handshake Detailed explanation:
2. TCP’s “four breakups”: Because TCP disconnection requires sending four packets, it is called four waves. Either the client or the server can actively disconnect. In socket programming, either party can perform a close() operation to generate a breakup operation. The long connection and short connection of the HTTP protocol are essentially the long connection and short connection of the TCP protocol. How do short connections and long connections work? What are their advantages?
|
<<: IoT Observation: Seven benefits of LoRaWAN technology application in one article
>>: Big data changes both ends of the web hosting market
What we are going to talk about today is other co...
The Internet of Things is the only way to the int...
In 2017, more and more operators around the world...
In November 2023, the "China Enterprise &quo...
[51CTO.com original article] At the just conclude...
[51CTO.com original article] In the Internet era,...
Kurun is a domestic merchant founded in 2019. Its...
The "speed up and reduce fees" policy h...
MWC2021 Shanghai has fully demonstrated the achie...
[Restocked again on 10.15] Bandwagonhost has launc...
Currently, Ethernet technology is widely used in ...
Preface When we browse the web, watch videos, and...
Hello everyone, today I would like to talk to you...
April 23, 2021, Beijing - The 2021 Cisco Automoti...
[51CTO.com original article] Cloud computing has ...