The connection revocation process involves the following four processes: 1. the application on host1 closes its connection, causing TCP to send a fin message to host2. 2. host2 sends a confirmation message to host1, and host2 submits fin as EOF to the application on host2. 3. After a period of time, the application on host2 closes the connection over it and triggers a fin message to host1. 4. host1 sends a confirmation message to host2. then, host2 closes the connection and releases the resource. However, host1 does not close the connection, but enters the time_wait status and sets the maximum survival time of the two segments (2msl) this status is retained.
Why do we need time_wait?
1. in step 4, The ack sent by host1 may be lost, causing host2 to resend the fin message, and time_wait maintains the connection status. what will happen if host1, the owner of the active shutdown, does not enter the time_wait status and closes the connection? When the re-transmitted fin message arrives, because TCP no longer has connection information, it uses RST (restart) to respond to the message, resulting in host2 entering the wrong status rather than the ordered termination status, if the last ACK message sent is in the time_wait status and the connection information is still recorded, it can correctly respond to the fin message of the Peer host2. 2. time_wait provides the time for the "outlier segment" in the connection to disappear from the network. consider what will happen if the delay or retransmission segment arrives after the connection is closed? Generally, TCP only discards the data and responds to the RST message, so this will not cause any problems. When the RST message arrives at the host that sends the delay segment, it also discards the segment because the host does not record any connection information. However, if a new connection with the same port number is established between two identical hosts, the outlier segment may be considered as a new connection, if any serial number of the data in the outlier segment is in the current Receiving Window of the new connection, the data will be re-received, and the result is that the new connection is damaged.
From: http://blog.csdn.net/lllxy/archive/2007/09/07/1776243.aspx