TCP protocol three-way handshake process

TCP (Transmission Control Protocol) Transmission Control Protocol

TCP is a host-to-host layer transmission control protocol, providing reliable connection services, using three-way handshake confirmation to establish a connection:

The bit code is the tcp flag bit, and there are 6 kinds of signs: SYN (synchronous connection establishment) ACK (acknowledgement confirmation) PSH (push transmission) FIN (finish end) RST (reset reset) URG (urgent emergency)

Sequence number Acknowledge number

The first handshake: Host A sends a bit code of syn=1, and randomly generates a data packet with seq number=1234567 to the server. Host B is known by SYN=1, and A requests to establish a connection;

The second handshake: Host B needs to confirm the online information after receiving the request, and sends ack number=(host A's seq+1), syn=1, ack=1, and randomly generates a packet of seq=7654321

The third handshake: After host A receives it, check whether the ack number is correct, that is, whether the seq number+1 sent for the first time, and whether the bit code ack is 1, if it is correct, host A will send the ack number=(host B's seq+1), ack=1, after the host B receives it and confirms the seq value and ack=1, the connection is established successfully.

After completing the three-way handshake, host A and host B begin to transmit data.


In the TCP/IP protocol, the TCP protocol provides reliable connection services and uses a three-way handshake to establish a connection. 
The first handshake: When the 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; 
the second handshake: The server receives the syn packet and must confirm the client's SYN (ack= j+1), at the same time, it also sends a SYN packet (syn=k), that is, a 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 to the server ACK (ack=k+1), after the packet is sent, the client and server enter the ESTABLISHED state and complete the three-way handshake. After completing the three-way handshake, the client and server begin to transmit data.

Example:

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

The first handshake: 192.168.1.116 sends bit code syn=1, randomly generates data packets with seq number=3626544836 to 192.168.1.123, 192.168.1.123 knows from SYN=1 that 192.168.1.116 requests to establish a connection;

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, and randomly generate a packet of seq=1739326486;

The third handshake: After 192.168.1.116 receives it, check whether the ack number is correct, that is, the seq number+1 sent for the first time, and whether the bit code ack is 1. If it is correct, 192.168.1.116 will send ack number=1739326487 again, ack=1, 192.168.1.123 confirms seq=seq+1, ack=1 after receiving it, the connection is established successfully.

 

Illustration:
A three-way handshake process (Figure 1, Figure 2)

 

(Picture 1)

(Picture 2)
 

 

The flag bit of the first handshake (Figure 3)
we can see that there is only one synchronization bit in the flag bit, that is, the request (SYN)
3 
 (Figure 3)

The flag bit of the second handshake (Figure 4)
we can see There is a confirmation bit and a synchronization bit in the flag bit, that is, the response (SYN + ACK)
4 
(Figure 4)

The flag bit of the third handshake (Figure 5)
We can see that there is only one confirmation bit in the flag bit, which is Do re-confirmation (ACK)
5 
 
(Figure 5)

A complete three-way handshake is request-response-reconfirmation

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326991742&siteId=291194637