Reliable transmission of TCP

Accumulation confirmation method:

The receiver generally adopts the method of accumulative confirmation. That is, it is not necessary to send acknowledgments to the received packets one by one, but to send an acknowledgment to the last packet that arrives in sequence, which means that all packets up to this packet have been received correctly.

Advantages: easy to implement, no need to retransmit even if the acknowledgment is lost.

Disadvantage: Can not reflect to the sender all the packets that the receiver has received correctly.

Sliding window in bytes

Let the sender be A and the receiver be B.

Without receiving confirmation from B, A can continuously send all the data in the window. Any data that has been sent must be temporarily retained until an acknowledgment is received, so that it can be used during retransmission over time.

A's send window must not exceed the value of B's ​​receive window.

The size of the sending window of the sender is also restricted by the degree of network congestion at that time.

The latter part of the trailing edge of the send window indicates that it has been sent and an acknowledgment has been received. There is no need to keep this data anymore. It is not possible for the trailing edge of the send window to move backwards because the acknowledgment that has been received cannot be undone. The front edge of the sending window usually moves forward continuously, but it may not move, which corresponds to two situations: ① no new confirmation is received; ② new confirmation is received, but the window notified by the other party has shrunk, making the leading edge of the sending window Just don't move.

The TCP standard strongly discourages the sending window being contracted backwards.

If the data sent by A is not confirmed by B, in order to ensure reliable transmission, A can only think that B has not received the data. Then, A will retransmit this part of data after a period of time (controlled by the timeout timer), and reset the timeout timer until the confirmation of B. If the confirmation number received by A falls within the sending window, then A can continue to slide the sending window forward and send new data.

If a received packet is detected with errors, it is discarded. If the receiving application does not have time to read the received data, the receive buffer will eventually fill up, reducing the receive window to zero. Conversely, if the receiving application can read the received data from the receiving buffer in time, the receiving window can be increased, but the maximum cannot exceed the receiving buffer size.

From the above discussion, the following three points should be emphasized:

1. Although A's sending window is set according to B's receiving window, at the same time, A's sending window is not always the same size as B's receiving window. This is because there is a time lag (which is still indeterminate) to transmit the window value over the network. In addition, sender A may appropriately reduce the value of its own sending window according to the current congestion situation of the network.

Second, the TCP standard does not clearly stipulate how to deal with data that arrives out of sequence. Usually, in order to improve the utilization of network resources, TCP temporarily stores the data that arrives out of sequence in the receiving window, and then delivers it to the upper-layer application in sequence after the missing bytes in the byte stream are received .

Third, TCP requires that the receiver must have the function of accumulating acknowledgments, which can reduce the transmission overhead. The recipient can send an acknowledgment when appropriate, or can piggyback on the acknowledgment when it has data to send. But please pay attention to two points: First, the receiver should not delay sending the acknowledgment too much, otherwise it will lead to unnecessary retransmission by the sender, which will waste network resources. The TCP standard specifies that acknowledgments should be delayed for no more than 0.5 seconds. If a sequence of segments of the maximum length is received, an acknowledgment MUST be sent for every other segment [RFC 1122]. The second is that piggybacking acknowledgments doesn't actually happen very often, since most applications rarely send data in both directions at the same time.

        Finally, it is emphasized that TCP communication is full-duplex communication. Each party in the communication is sending and receiving segments. Therefore, each party has its own send window and receive window. When talking about these windows, be sure to figure out which side is the window.

 

 

Guess you like

Origin blog.csdn.net/u012632105/article/details/123652844