Why can a TCP connection only have "3-way handshake" and not 2 or 4?

Why can a TCP connection only have "3-way handshake" and not 2 or 4?

We know that the communication modes between client A and server B can be divided into: full-duplex, half-duplex, and simplex:

  • Simplex: A can send to B, but B cannot send to A. This is called simplex
  • Half-duplex: A can send to B, and B can also send to A, but the two steps cannot be performed at the same time. That is, when A sends a message to B, B cannot send a message to A.
  • Full-duplex: That is, while client A is sending information to server B, server B can also send information to client A.

TCP is full-duplex.

[[264229]]

How TCP works

Next, I will show you how TCP works.

From the previous knowledge, we learned that TCP has three handshakes (previous reference: HTTP also has long and short connections? HTTP long connection vs short connection).

Schematic diagram of TCP's three-way handshake:

The specific meaning can be understood as follows:

1. A handshake

The client wants to send a packet to the server with the SYN flag set to 1 and the initial sequence number X, which is encapsulated in the sequence number field in the packet header.

The client enters the SYN_SEND state and waits for confirmation from the server.

2. Second handshake

The server sends back an ACK (acknowledgement packet), setting both the SYN and ACK flags to 1, and modifying the sequence number to X+1.

At the same time, it also sends a packet, a SYN packet, with a sequence number (seq = Y), that is, a SYN + ACK packet.

At this point the server enters the SYN_RECV state.

3. The third handshake

The client receives the (ACK+SYN) packet sent by the server, and the SYN flag is 0. The ACK flag is 1.

At the same time, add 1 to the sequence number field of the ACK packet sent by the server and put it in the packet, and send it to the server, that is, ACK=Y+1.

Popular explanation:

Do you still find it difficult to understand? Let me give you an example.

First, we assume that A and B are the two parties communicating this time. Sending a message represents a handshake.

  • A handshake: A sends a WeChat voice chat to B, "Are you there? Can you hear me?"
  • Second handshake: B received a WeChat voice call from A, and then said to A: Well, I am here, I can hear you, can you hear me, what's the matter?
  • The third handshake: A received a voice message from B, I want to ask you something?

Then we started a pleasant chat.

Is a two-way handshake possible?

So let's explore whether two handshakes are possible.

  • After a handshake: Server B can receive information sent by client A, but client A cannot be sure whether the message it sent is successful.
  • After the second handshake: Server B sends a message to Client A. Server B can think that the message I sent was successful.
  • If there is no third handshake now, server B will think that our connection is successful after the second handshake.

But what about client A? There is no guarantee that it will receive the information sent by server B. What if client A does not receive the information sent by the server?

The client will think that the communication between us has not been established. Such a communication process is obviously unsuccessful.

If there are a large number of such cases, Server B will crash.

It seems that only two handshakes are not enough to complete the working principle of TCP communication.

If two times is not enough, what about four times?

Is a four-way handshake OK?

According to the TCP communication principle above, we know that after the three-way handshake, client A and server B can both confirm the messages they sent before, and each can receive and send the messages to the other party successfully.

According to the above conclusion, whether you shake hands four times or five times, it is futile, because after the "three handshakes", everything that needs to be done has been done.

in conclusion

TCP's three-way handshake is a classic, and the communication protocols on computers are also based on TCP's three-way handshake and four-way handshake.

Because the direct communication between computer applications is based on the HTTP protocol, and HTTP is actually implemented by the TCP protocol, which has been mentioned before.

  • TCP can only have three handshakes, not two or four.
  • If there are less than three handshakes, it cannot be guaranteed whether the communication connection is established;
  • Any more than three handshakes is futile and wasteful.

We can see that after three handshakes, we can draw the following conclusions:

  • A can now send messages to B, and A can also receive messages from B;
  • At the same time, for B, B can also send messages to A, and B can also receive messages sent by A.

<<:  It turns out that you can understand the next generation of Wi-Fi in such an easy-to-understand way

>>:  What should you do if you forget the wireless router backend login address?

Recommend

Six key trends in network management

We live in an era of rapid development of IT tech...

China Huaxin and Nokia jointly established "Shanghai Nokia Bell"

China Huaxin Post and Telecommunications Economic...

The battle for lightweight wide area networks: What makes LoRa different?

Technically, the various WAN technologies vary du...

The iPhone 12 finally uses 5G, but is it really too late?

At the Apple conference this morning, the most ex...

Share | Basic knowledge of 5G wireless network

Wireless networks have improved dramatically over...

To be successful in 2018, operators need to rely on these three strategies

The story of 2017 has come to an end. On the surf...

Overview of 5G Industry Terminal Development

With the continuous development of the fifth gene...

How to deal with the four major challenges of edge computing

Edge computing use cases are broad and its early ...

SKT launches online-only plans for 5G and 4G customers

South Korean telecom operator SK Telecom recently...

Ten underutilized SD-WAN features

SD-WAN is more than just an alternative to Multip...