Why does TCP require three handshakes instead of two?

Why does TCP require three handshakes instead of two?

Hello everyone, I am the island owner Xiaofeng. Today I will talk about why TCP needs 3 handshakes instead of 2.

Suppose there is a river, and there are two people upstream and downstream of the river. These two people can only communicate with each other through the river:

picture

There were many leaves on the shore, so they wrote the message on the leaves on the shore:

picture

And assume that leaves upstream will float downstream, and leaves downstream will float upstream.

picture

However, due to the effect of water flow, the leaves that set out first in the same direction may arrive later (out of order) or may sink into the water (be lost).

That is to say, if a sends four leaves, each with two words written on it, recording "Coder's desert island survival", a puts [Coder] [desert] [island survival] [survival] into the river in sequence, after these four leaves reach b, they may become [island survival] [Coder] [survival] [desert] (random order), or one leaf may be lost, becoming [desert] [Coder] [survival] (random order + data loss):

picture

So in this case, how can we let B know that what A actually wants to say is "The Survival of a Coder on a Deserted Island"?

It's very simple, with only two mechanisms: numbering and confirmation.

The numbering mechanism is aimed at the disorder problem, and the confirmation mechanism is aimed at the loss problem.

Each leaf that a puts into the river is given a number, which increases in sequence. After receiving the leaves, b reassembles them according to the numbers. In this way, even if the leaves arrive in a disordered order, b can still restore the information according to the numbers:

picture

The disorder problem is solved, and the leaf loss problem relies on the confirmation mechanism: after receiving each leaf, b will reply with a received message, and attach the number of the received leaf + 1, which is the number of the next leaf expected to be sent by a:

picture

In this way, after a receives [3 received], it is sure that b has received [2 荒]. If a does not receive [3 received] within a certain period of time, it will pick up a leaf and send [2 荒] again.

picture

It can be seen that this retransmission mechanism ensures that the information can be sent to b even if the leaf may sink into the water.

With the numbering and confirmation mechanism, a can reliably transmit information to b even in an unreliable medium like a river.

Of course, b can also use this mechanism to send messages to a reliably.

Since each leaf needs to be numbered, a must tell b the initial number of the leaf before sending a message to b. Because b can also send messages to a, both parties must know the initial number of each other's leaves before communication, so that they can correctly confirm the receipt of the leaves and re-arrange the leaves according to the number.

picture

So both parties AB agreed that the chat initiator would first tell the chat receiver the number, and the chat receiver would also tell the initiator his own number after receiving the initiator's number.

Still assuming that a initiates the communication first, a first sends a leaf with "SYN X" written on it. SYN means that this is a leaf that tells you my initial number (in TCP, SYN is the abbreviation of synchronization, but its function is the same as here), and X means its own initial number.

picture

According to the confirmation mechanism mentioned earlier, b needs to confirm the leaf after receiving it, so b sends a leaf: "ACK X+1", which means "I confirm that I have received your leaf and look forward to receiving leaf number X+1" (ACK is the abbreviation of acknowledge in TCP, which means confirmation, and its function is the same as here).

picture

Don't forget that b also needs to tell a its own number, so b immediately sends another leaf "SYN Y", which means "this is a leaf telling you my initial number, my initial number is Y":

picture

Similarly, a also needs to confirm after receiving it, so a sends a leaf: "ACK Y+1", which means "I confirm that I have received your leaf and look forward to receiving your leaf number Y+1."

picture

After at least four leaves, A and B can know each other's initial number. Pay attention here:

picture

It can be seen that both leaves are sent from b to a, so the information of these two leaves can be merged together, so that one less leaf can be sent:

picture

It can be seen that both parties need to send at least 3 leaves to know the other party's initial number, and this cannot be guaranteed if only two leaves are sent.

<<: 

>>:  Report: Global Satellite IoT Market Users to Reach 26.7 Million in 2028

Recommend

5G unlocks new solutions for the medical industry

5G unlocks new solutions for the medical industry...

Is LoRaWAN the solution to cellular IoT challenges?

Ten years ago, there were high hopes for cellular...

Under the epidemic, IDC companies have no right to complain

At present, with the effective and orderly implem...

Five realistic predictions for enterprise IT in 2018

As 2017 is coming to an end, many companies are p...

6G is coming? Is it too early to start 6G research now?

With the implementation of 5G, the direction of m...

Modernizing Configuration Management to Address Network Complexity

The expansion of network infrastructure to multip...

edgeNAT Korea/Hong Kong KVM 20% off, top up 500 yuan and get 100 yuan free

edgeNAT is a Chinese VPS hosting company establis...

my country will open 1.4 million 5G base stations by the end of the year

This year is a period of large-scale 5G construct...

Network Access Control-Network Address Translation

With the development of the Internet and the incr...

230,000 new cases every day: How they are "used by 5G"

"Why are users required to activate 5G cards...