Why is the TCP connection a three-way handshake, not a two-way handshake or a four-way handshake?

Why is the TCP connection a three-way handshake, not a two-way handshake or a four-way handshake?

The text is reproduced from the official account: Programmer Qiaogeli (ID: CXYqiaogeli). If you need to reprint, please contact the original official account.

[[265124]]

Brother Qiao: You said, "Hello, hello, can you hear me?", which is the first handshake, which means that Xiao Meng, your ability to send messages is fine. Then I replied, "Xiao Meng, I can hear you, can you hear me?" This is the second handshake. I replied to you, which means that I can hear you (which means that I have the ability to receive messages). My saying "Can you hear me?" also means that I also have the ability to send messages. By the end of the second handshake, it means that I have the ability to send and receive messages, and Xiao Meng, you have the ability to send messages. Then you said, "Brother Qiao, I heard you," which is the third handshake. You heard me, which means that Xiao Meng, your ability to receive messages is fine. In this way, you can talk (TCP connection is established)

Xiao Meng: "Hey, Brother Qiao, can you hear me?"

Brother Qiao: "Brother Qiao can hear me, Xiao Meng, can you hear me?"

Xiao Meng: "Xiao Meng can hear Brother Qiao, can Brother Qiao hear Xiao Meng?"

Xiao Meng: 1. Two handshakes. I think this is because the server has received the message from the client and knows that the client can send messages. However, since there is no third handshake, the server does not know whether the client has the ability to receive messages.

2. The client receives the message from the server. The client replies only after knowing that the server has received my message, which means that the server's ability to receive and send messages is fine (the server has sent the message);

3. In summary, the client ensures that there is no problem with the server's reception and sending, but the server only knows that there is no problem with the client's sending message, which is not reliable, so the two-way handshake is not allowed.


Chogori: Let me give you an example. Suppose the client and server establish a TCP connection, and then the first TCP connection request sent is blocked.

Since the client did not receive the response message from the server, the client thought that the TCP connection request was lost, so it resent the TCP connection request. This time there was no blocking and the connection was successfully established. Because it was a two-way handshake, communication can be carried out with only two connections.

The communication ended and then the connection was disconnected.

At this time, the client thought that the initially blocked connection request A was lost, but it was not lost, it was just blocked. After being blocked for a while, the network became unblocked again, so TCP connection request A successfully reached the server. The server thought that the client wanted to transmit data again, so the server responded to the connection request again, and after two handshakes, the TCP connection was successfully established again.

However, since the client thinks that the connection request has been lost, it will not use the established connection request for data communication. Although the server allocates resources to the client, the client does not transmit data, which wastes the server's resources. Imagine if the network is very congested, then when the network becomes unblocked, the server will waste a lot of resources and may not be able to process normal connection requests!

The server did not receive a reply after a long time (specified time and client), so it would not allocate resources to the client and the connection would be abandoned.

Author: Qiao Geli, Baidu engineer. Personal WeChat public account: Programmer Qiao Geli ( ID : CXYqiaogeli )

<<:  How to improve WiFi signal without changing wireless router

>>:  It turns out that the HTTP protocol is so simple! Understand HttpServletRequest in one article

Recommend

20,000 words of detailed explanation! 32 classic questions about Netty!

Introduction Hello everyone, I am Tianluo. When w...

"Innovation City" shines brightly and opens up a new ecosystem for Ascend

[[337542]] On August 11, 2020, the DevRun Develop...

Will 5G replace NB-IoT immediately after commercialization? Not really!

From May 21 to May 25, the international telecomm...

Token: How to reduce the traffic pressure of user identity authentication?

Many websites usually use the Session method to i...

Huawei and its global partners work together to build a full-scenario smart life

【51CTO.com original article】 Normal 0 7.8 磅 0 2 f...

Why SDN and IBN Require Better Network Visibility

Intent-based networking (IBN) has been a topic of...

Practical analysis of network log correlation on OSSIM platform

This article mainly conducts an in-depth analysis...

My HTTP/1.1 is so slow! What can I do?

[[383004]] This article is reprinted from the WeC...