Detailed TCP / IP three-way handshake

  • Definition of three-way handshake
  • The purpose of the three-way handshake
  • The process of three handshake
  • Why do we have to shake hands three times?

> Definition of three-way handshake

Three-way handshake (three times handshake; three-way handshake) The so-called "three-way handshake" is how to track the amount of data sent each time to negotiate to synchronize the transmission and reception of data segments, according to the amount of data received The number of data confirmations and when to cancel the contact after the data is sent and received, and establish a virtual connection. In order to provide reliable transmission, TCP sends the sequence numbers of the data packets in a specific order before sending new data, and needs confirmation messages after these packets are transmitted to the target machine. TCP is always used to send large amounts of data. TCP is also used when the application needs to make an acknowledgment after receiving the data.

> The purpose of the three-way handshake

Eliminate the interference of the old connection request SYN message to the new connection, synchronize the serial number and confirmation number of both sides of the connection and exchange TCP window size information.

> Three handshake process

Write a picture description here

The first handshake: the client sends a syn packet (syn = x) to the server and enters the SYN_SEND state, waiting for the server to confirm; the
second handshake: the server receives the syn packet and must confirm the client's SYN (ack = x + 1) , At the same time, I also send a SYN packet (syn = y), that is, SYN + ACK packet, and the server enters the SYN_RECV state; the
third handshake: the client receives the SYN + ACK packet from the server and sends an acknowledgement packet ACK (ack = y + 1), after the packet is sent, the client and server enter the ESTABLISHED state and complete three handshake.
The packet transmitted during the handshake does not contain data. After the three handshake is completed, the client and the server officially start transmitting data. Ideally, once a TCP connection is established, the TCP connection will be maintained until either of the two parties actively closes the connection.

> Why do we have to shake hands three times?

1. The three-way handshake is used to prevent the invalid connection request message segment from being suddenly transmitted to the host B, thus generating an error. The invalid connection request message segment means that the connection request sent by host A has not received confirmation from host B. After a period of time, host A sends a connection request to host B again, and the establishment is successful, and the data transmission is completed in sequence. Consider such a special case, the first connection request sent by host A is not lost, but because the network node causes a delay to reach host B, host B thinks it is a new connection initiated by host A, so host B agrees to connect, and A confirmation is sent back to host A, but at this time host A simply ignores it, and host B has been waiting for host A to send data, resulting in wasted resources of host B.
2. Of course not. The reasons are as above.

Published 19 original articles · praised 5 · visits 7742

Guess you like

Origin blog.csdn.net/qq_38119372/article/details/79538381