This paper is participating in theNetwork protocols must be known and must be known”Essay campaign

TCP waved four times

Four-way Wavehand is the termination of TCP connection. When the TCP connection is disconnected, the client and server need to send a total of 4 packets to confirm the disconnection. In Socket programming, this process is triggered by either the client or the server executing a close

Because TCP link is a full-duplex, therefore each direction must be shut down alone, this principle is when one party after complete data to send, to send a FIN links to terminate this direction, received the FIN just represent the direction of no data flow, not in the received data, but still can send data in the TCP link, also know the direction When a FIN is sent, the first party to close will actively close, while the other party will passively close.

1. First wave: The client sends the FIN flag with the sequence number seq=W to close the transmission from the client to the server. The client enters the FIN_WAIT_1(terminate wait 1) state. Second wave: After receiving the FIN flag, the server sends an ACK to the client, confirming that the sequence number is +1(the same as SYN, one FIN occupies one sequence number), and carries its own sequence number seq=Y. The server enters CLOSE_WAIT state 3. Third wave: The server sends the FIN flag (seq=Y) to disable data transfer from the server to the client. The server enters the LAST_ACK state 4. Fourth wave: After receiving the FIN flag, the client enters the TIME_WAIT state and sends an ACK =1. The ACK sequence number is the received sequence number +1, that is, ACK =Y+1. As soon as the server receives an acknowledgement from the client, it immediately enters the CLOSED state and completes the four-time wave