reference
Why is TCP three-way handshake, rather than two or four?
1. tcp three-way handshake process
The figure shows that the three-way handshake tcp key, switch acknowledgment sequence number seq.
2. Why can not two-way handshake
Because the client and server, the two sides on the other side of the serial number to confirm that the key to reliable transmission.
Two-way handshake is as follows:
- A transmits the synchronization signal SYN + A's Initial sequence number
- B transmits a synchronization signal SYN + B's Initial sequence number + B's ACK sequence number
When the second step of the action is completed, we can ensure that B has its serial number A , because the second step is performed only after the first step to success. But it does not guarantee its serial number B is A , a second step since the transmission may fail.
After two handshake is complete, as we assume, tcp only the second handshake, then the secondary handshake is completed, B have to think the connection has been established, no matter handshake second transmission was successful .
Then, if the second transmission failed handshake, A will not receive the serial number B, B will not be able to determine the start of data transmission in the first few numbers.
In this case, some of the transmitted data B (TCP full duplex communication, the server B may take the initiative to send a message to the client A) to A, together with the serial number 20000, was received A:
A this time faced with the embarrassment of two choices:
- A data packet may be maintained. But the starting sequence number of A Company B did not know, the packet to be saved when, in order to respond to ACK it?
- A can reply ACK. ACK indicates the meaning of bytes of data before its serial number have been received, but the start sequence number A B even not know: a starting sequence number may be 100, and may be 1000, A can not determine which Lacks number of bytes , it is even more afraid to respond to the ACK.
So, no matter which choice is inappropriate. This is because there is no confirmation A serial number B's.
In tcp by three-way handshake, and packet loss processing mechanism, A and B will be determined by its own serial number received counterpart.
3. tcp to handle packet loss in the three-way handshake
Copy from TCP three-way handshake why, instead of twice or four times?
In addition to using tcp three-way handshake, but also unexpected loss of proper disposal to ensure that A, B sides and the serial number of the transmission confirmation.
- If the first packet, i.e. send SYN A is lost midway B, B does not reach the
A retransmission timeout periodically until a confirmation of receipt of B - If the second packet, i.e., B is sent to A SYN + ACK is lost midway does not reach A
B periodically timeout retransmission until acknowledged receipt of A - If the third packet, i.e. send ACK A is lost midway B, B does not reach the
A finished ACK, the Established state unilaterally that TCP, TCP and B is in Active state clearly that:
. A case is assumed that neither data transmission, retransmission timeout B periodically, until it receives confirmation of a, B, after receiving the TCP connection
is also Established state, can be a two-way contract.
B. A case is assumed that data is sent, B Data + ACK received A's, the natural state is switched to established and accepted the A
Data (Send ACK way while the tape Data).
c. B assumes data transmission, data transmission or not, will have periodic retransmission timeout SYN + ACK, until it receives confirmation of A can send data (A did not receive the confirmation, the connection is not established, it can not transmit data ).
In this way, tcp three-way handshake, coupled with loss of handling mechanism, ensures that the acknowledgment A, B on both sides of the serial number. It will establish the basis for reliable transmission.
4. Why can not handshake
The second and third steps in the four-way handshake combined, is a three-way handshake. To improve efficiency, it is the merger of the second and third step.