Premise:
(1) SYN (synchronous set up online)
(2) ACK (Acknowledgement confirmation)
(3) PSH (push transfer)
(4) FIN (end of finish)
一、三次 handshake
(1) First handshake: The client sends the SYN packet (SYN=X) to the server and enters the syn_send state , waiting for the server to confirm;
(2) The second handshake: the server receives the SYN packet, must confirm the customer's SYN (ACK=X+1), simultaneously also sends a SYN packet (syn=y), namely the Syn+ack packet , at this time the server enters the syn_recv state ;
(3) The third handshake: the client receives the server's Syn+ack packet, sends the acknowledgment packet ack(ack=y+1) to the server, and after the packet is sent, the client and server enter the established state and complete three handshake.
The packets delivered during the handshake do not contain data , and after the three handshake is completed, the client and server formally begin transmitting the data. Ideally, once a TCP connection is established, the TCP connection will persist until either side of the communication is actively shutting down the connection.
二、四次 waved.
(1) The first handshake: the active shut-off party sends a fin packet to close the active side of the data transfer, (before the fin packet sent out data, if not received ACK acknowledgement message, the active side will still resend the data) but at this time the active closed side can also accept the data.
(2) Second wave: The passive closing party receives the fin packet, sends an ACK packet to the other party, confirms that the serial number is received sequence number +1, (same as Syn, a fin occupies a serial number).
(3) Third wave: The passive shut-off party sends a FIN packet to turn off the passive shutdown to the active shut-off side of the data transfer. (data transfer off)
(4) Wave for the fourth time: the active closing party receives FIN, sends an ACK packet to the passive closing party, confirms the serial number to receive the serial number +1, at this point, completes four times the wave.
TCP three-time handshake and four-time wave