Analysis on three-way handshake process of TCP transmission control protocol
TCP (Transmission Control Protocol) is the Transmission Control Protocol of the host to the host layer. It provides reliable connection services and uses three-way handshakes to establish a connection: the bit code is the TCP flag bit, there are 6 tags: SYN (synchronous established online) ACK (acknowledgement confirmation) PSH (push transfer) FIN (finish ended) RST (reset) URG (urgent) sequence number (Sequence number) Acknowledge number (confirmation number) first handshake: host A sends A bid of syn = 1, and generates A packet of seq number = 1234567 to the server at random, host B is known by SYN = 1, and A requires online connection; second handshake: after receiving the request, host B needs to confirm the online information and send ack number = (seq + 1 of host A) to host ), syn = 1, ack = 1, random generation of seq = 7654321 packet third handshake: host Check whether the ack number is correct after receiving it, that is, the seq number + 1 sent for the first time, and whether the ack is 1. If yes, host A will send ack number = (seq + 1 of host B), ack = 1 again. After host B receives the message, confirm that the seq value is set to ack = 1, and the connection is established successfully. After three handshakes are completed, data is transmitted between host A and host B.
In TCP/IP, TCP provides reliable connection services and uses three handshakes to establish a connection.
First handshake: when a connection is established, the client sends the syn Packet (syn = j) to the server and enters the SYN_SEND status. Wait for the server to confirm;
The second handshake: when the server receives the syn packet, it must confirm the customer's SYN (ack = j + 1) and send a SYN Packet (syn = k), that is, the SYN + ACK packet, the server enters the SYN_RECV status. The third handshake: the client receives the SYN + ACK packet from the server and sends the ACK (ack = k + 1) Confirmation packet to the server, the client and server enter the ESTABLISHED status and complete the three-way handshake. After the three handshakes are completed, the client and the server start to transmit data. instance: IP 192.168.1.116.3337> 192.168.1.123.7788: S 3626544836: 3626544836
IP 192.168.1.123.7788> 192.168.1.116.3337: S 1739326486: 1739326486 ack 3626544837
IP 192.168.1.116.3337> 192.168.1.123.7788: ack 1739326487, ack 1 first handshake: 192.168.1.116 sends a location code syn = 1, and randomly generates packets with seq number = 3626544836 to 192.168.1.123, 192.168.1.123 is online according to SYN = 1 to know 192.168.1.116. The second handshake: 192.168.1.123 should confirm the online information after receiving the request, and send ack number = 3626544837, syn = 1, ack = 1 to 192.168.1.116, generates packets with seq = 1739326486 at random. The third handshake is 192.168.1.116. After receiving the packets, check whether the ack number is correct, that is, the seq number + 1 sent for the first time, and whether the ack is 1. If yes, 192.168.1.116 then sends ack number = 1739326487, ack = 1, After receiving the message, 192.168.1.123 confirms that seq = seq + 1 and ack = 1, the connection is established successfully. Illustration:
A three-way handshake process (Figure 1, Figure 2)
(Figure 1)
(Figure 2)
The flag of the first handshake (figure 3)
We can see that there is only one synchronization bit in the flag, that is, the request (SYN)
(Figure 3)
The flag of the second handshake (Figure 4)
We can see that there is a confirmation and synchronization bit in the flag, that is, the response (SYN + ACK)
(Figure 4)
The flag of the third handshake (figure 5)
We can see that there is only one confirmation bit in the flag, that is, re-confirmation (ACK)
(Figure 5)
A complete three-way handshake, that is, request-response-confirm again