The three-way handshake is a concept of transport layer TCP protocol in the network seven-layer model. TCP uses three-way handshaking in order to realize reliable byte stream service (sending data accurately and reliably to each other).
Three handshakes diagram
Note: SYN(Synchronize) ACK(Acknowledgement) confirmation
The image is quoted from illustrated HTTP
First handshake: The sender sends a packet with the SYN flag. (Make a request)
Second handshake: The recipient replies with a PACKET with the SYN/ACK flag. (Acknowledge receipt and initiate request)
Third handshake: After receiving the packet, the sender replies with an ACK flag. (Acknowledgement of receipt)
The above is the concept of three handshakes, I believe that you are more or less familiar with or familiar with. But why three, not two or four?
This is because a three-way handshake lets both parties know that there is no problem with receiving and sending.
explain
First handshake: Through the first handshake, the receiver can know that the data sent by the sender is ok with its own data received.
Second handshake: By the second handshake, the sender knows that its sending and receiving data is ok (because it received an ACKh/SYN packet from the receiver) and that its sending data is ok.
Third handshake: Through the third handshake, the receiver can know that its sent data and the received data of the sender are ok. At this point, both parties know that they and the other party have no problem sending and receiving data, and can establish a connection for communication.
Two shake hands
Here’s how the two handshakes work:
First time: USER A sends A request to user B, and user B receives the request.
The second time :B sends A request to A, regardless of whether A answers the request or whether A hangs up. Start making connections. I’m sending data to A.
After A sends the request for the first time, B does not receive it for A long time due to some reasons. During this period, A sends the request for many times due to timeout, and finally hangs up. After receiving the request, B thinks that A wants to establish A connection with it, and sends the confirmation (the second time). At this time, A new connection is established and B starts to send data. At this time, B has no idea about the situation of A (ignoring B’s confirmation or having hung up). B has wasted a lot of resources. So two handshakes is definitely not going to work.
Finally, why waste resources checking each other to see if the connection can be established when three handshakes will do? So there’s no need to shake hands four or more times.
This article can be regarded as my own reading notes, I hope to point out any mistakes, and I will correct them quickly!!
Reference: Illustrated HTTP, Interesting Network Protocols