In the previous section, Hongjue introduced the header format of TCP packet segments:

Are you Really Answering the RIGHT TCP interview Question? .

Today to tell you about TCP flow control is how to achieve it ~

Many of you have been asked in your interview what is the difference between flow control and congestion control. Before answering this question, you need to know what traffic control and congestion control are.

First of all, why flow control is needed. Generally speaking, we always want data to be transmitted faster, but if the sender sends data too fast, it may cause the receiver to fail to receive the data. As for flow control, the sending rate of the sender is not too fast, so that the receiver can receive it in time.

As an example, suppose that after TCP establishes A connection, receiver B tells sender A that the size of the receiver window (RWND) is 400 bytes:

At the beginning, B tells A that my RWND is equal to 400, so the sender’s send window cannot exceed the RWND given by the receiver. It is important to note that TCP is sent in packet segments, but the unit of TCP window is byte. Here we assume that each packet size of 100 bytes, and the data message section of the initial value of the hypothesis is 1 (the actual process is a random value) expressed in seq, uppercase ACK said confirmation, lowercase ACK said to confirm the value of the field (don’t understand children’s shoes must not see hong jue write of TCP packet first introduction, go reading again!) .

Through the images can be found, the host B carried out three times in total flow control, is the first time reduce the receiving window to RWND = 300, the second time reduced to 100, the last is reduced to zero, so the receiving window dynamic changing, it is reduced to zero, do not allow the sender to send data, unless the receiver to the sender to a new window value. Note that ACK also needs to be set to 1 when telling the sender the window value, because only ACK = 1 is valid.

I wonder if you have considered such A problem. If B sends A packet segment of window 0 to A and B’s cache has idle space, B sends A packet segment of RWND = 400 to A, but this packet segment is lost during transmission. A cannot wait for the non-zero window notification sent by B, and B is also waiting for A to send data. This creates a deadlock of waiting for each other.

To solve this problem, TCP sets a persistent timer for each connection. When is this timer going to start? When either side of the TCP connection receives the 0 window notification from the other side, the duration timer is started. If the time expires, the other side will send a 0 window detection packet segment (containing 1 byte of data). The other side will give the current window value when confirming the detection packet segment. The party receiving the segment then resets the duration timer. If it’s not zero, then you can start transferring data.

Note that in TCP, even if the window is set to 0, the zero window detection packet segment, confirmation packet segment, and packet segment carrying emergency data must be received.

Ok, so much for flow control!

May everyone read this article with skepticism and explore how it works.

Road obstruction and long, the past for preface, the future for chapter.

Looking forward to our next meeting!