Three-time handshake (three times handshake;three-way handshake) so-called "three-time handshake" that is, the amount of data sent each time is how to track the data segment sent and received synchronization, based on the amount of data received and determined the number of data and data sent, When you have finished receiving the contact, and establish a virtual connection.
In the TCP/IP protocol, the TCP protocol provides a reliable connection service with a three-time handshake to establish a connection.
first handshake : When a connection is established, the client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waiting for the server to confirm;
Second handshake : The server receives the SYN packet, it must confirm the customer's SYN (ACK=J+1), and also send itself a SYN packet (syn=k), that is, the Syn+ack packet, when the server enters the SYN_RECV state;
Third Handshake : The client receives the server's Syn+ack packet, sends the acknowledgment packet ACK (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, and the handshake is completed three times.
With such a three-time handshake, the client establishes a reliable duplex connection with the server to begin transmitting data. The main purpose of the three-time handshake is to ensure that the connection is duplex, and that more reliable is ensured by the retransmission mechanism. But why do you have to do three handshake to ensure that the connection is duplex, not one at a time? Two times not?
Let's take a real-life example of two people in language communication to simulate a three-time handshake.
First session:
Wife let a go out soy sauce, halfway met a friend B, a asked a sentence: "Dude, have you eaten?"
Results B with headphones to listen to the song, did not hear, did not respond. A heart thought: Talk to you also have no tone, don't tell you, communication failure. The communication must be unsuccessful in the case that B accepts no information transmitted by a.
If b hears what a says, then the first conversation succeeds, and then the second conversation.
Second session:
B heard a said, but he is a foreigner, Chinese is not good, do not know what the meaning of a said and do not know how to answer, so casually answered a sentence learned Chinese: I went to the toilet. A listen to a laugh immediately, "go to the toilet to eat"? The road is different from the conspiracy, away from you, communication failure. Indicates that B failed to communicate correctly in the case of a failure to respond.
If b hears a words, makes the correct answer, and also carries on the rhetorical question: I eat, you? Then the second handshake succeeds.
The first two dialogues proved that B was able to understand the word "a" and could make a correct response. The third conversation follows.
Third session:
A just and B dozen a greeting, suddenly wife shout him, "You a dead, dozen a soy sauce why so half a day, see I go home how to pack you", a wife is strict, listen to frighten apart ran home, put B himself drying that. B thought: This what people ah, have, I also go home, communication failure. Fails to communicate if a statement cannot be answered.
If a has also made the correct answer: I also ate. Then the third dialogue succeeded, the two have established a smooth communication channels, and then began to continue to chat.
The second and third dialogues proved that a can understand what B says and can make the right answer. It can be seen that two people have effective language communication, the process of three dialogues is necessary.
in the same vein, we can understand why TCP requires three handshakes:
In order to ensure that the server can receive the client's information and can make the correct response to the first two times (first and second) handshake, in order to ensure that the client can receive information on the server and be able to make the correct response to the following two times (second and third) handshake.
Reference: http://www.jb51.net/network/65961.html
Talking about the TCP three-time handshake