TCP uses four types of timers: a retransmission timer, a persistence timer, a keepalive timer, and a time wait timer. The main features of these timers are as follows:
Retransmission timer
When TCP sends a packet segment, it creates a retransmission timer for the specific packet segment. Two things can happen:
- If an acknowledgement ACK is received for this particular message segment before the timer expires, the timer is dismissed.
- If the timer expires before acknowledgement of this particular message segment is received, the message segment is retransmitted and the timer is reset.
Continuous timer
Window size notification: recipients can receive cached data size; The receiver sends a window size notification to the sender before the sender can send data. If the receiver’s cache is full, a zero window size notification is sent to the sender.
To deal with zero window size notifications, TCP needs another timer.
Assume receiving TCP declares window size zero: sending TCP stops sending message segments until receiving TCP sends confirmation and declares a non-zero window size. But this confirmation can be lost. We know that in TCP, you don’t need to send acknowledgements for acknowledgements. If it confirms that it’s lost, the receiving TCP doesn’t know, it thinks it’s done, it waits to send TCP and then it sends more segments. However, as the sending TCP does not receive the confirmation, it waits for the confirmation to inform the size of the window. TCP on both sides is waiting for each other forever.
To address this deadlock wait situation, TCP uses a persistence timer for each connection. When sending TCP receives an acknowledgement with a window size of zero, the persistence timer is started. When the timer deadline is adhered to, sending TCP sends probe segments. This packet segment contains only one byte of data and has an ordinal number that never needs to be confirmed; It is even ignored when calculating validation of other parts of the data. The detection packet segment informs the peer party that the detection packet is lost and must be retransmitted.
Insist that the timer value is set to the value of the retransmission time. However, if no response is received from the receiver, another probe message segment is sent and the value of the persistence timer is doubled and reset. The sender continues to send probe segments, doubling and resetting the value of the persistence timer until the value increases to the threshold (usually 60 seconds). After that, the sender sends a probe segment every 60 seconds until the window reopens.
Life timer
A keepalive timer is used in some implementations to prevent long periods of idling between two TCP connections.
Suppose the client opens a connection to the server, transfers some data, and then goes silent. Maybe this customer is out of order. In this case, the connection handles the open state forever.
To solve this problem, most implementations have the server set a keepalive timer. Every time the server receives a message from the customer, it resets the timer. The timeout is usually set to 2 hours.
If the server does not receive a message from the customer after 2 hours, it sends a probe message segment. If 10 probe segments are sent, each 75 seconds apart, and no response is received, the client is assumed to have failed and the connection is terminated.
Time waiting timer
The 2MSL time wait timer is used during connection termination, i.e., TCP waves four times for the last time.
When TCP closes a connection, it does not consider the connection to be truly closed immediately.
The connection is in an intermediate state during the time wait. Repeat FIN packet segments arrive at the destination station and are discarded.
This timer is usually set to twice the expected lifetime of a message segment.
Attached: TCP four waves (client active shutdown) :
1 The client sends a FIN request packet to the server (the socket closes the channel for sending data).
2 After receiving the FIN packet, the server sends an ACK packet to the client, indicating that it agrees to close the link.
3 If the recV of the server is unblocked and the data return length is 0, ensure that the client is disconnected.
4 The server sends a FIN packet requesting disconnection to the client.
5 The client receives the FIN packet and sends the ACK packet to the server.
6 The client enters 2MSL time at the same time. If the server does not receive the FIN of the server again when time_wait arrives, the server is shut down after receiving its ACK packet and the client is disconnected (the socket closes the channel for receiving data). If the SERVER receives a FIN packet again, the server sends the ACK packet again and resets time_wait until the packet is normal.