Generally speaking, we want the data to be transmitted faster , But if it's sent too fast , It may cause the receiving party to have no time to receive , Cause data loss .
So called flow control , That is to make the sending rate of the sender not too fast , Give the receiver time to receive . Using sliding windows
The mechanism can be easily used in TCP The flow control of the sender is realized on the connection . The following is an example .
A and B Has been established between TCP connect ,A The sending window size of is 400 byte , The size of each segment is 100 byte .A Start to step by step B send data , When sending the second 3 Segment data , A loss occurred .
here ,A Received from B Confirmation message of , Confirm that the contents of the first two paragraphs have been received , And adjust the receiving window to 300 byte .
After receiving the confirmation message ,A Move the sending window forward two segments , The data of the first two paragraphs can be deleted . At this time, there are 201-500 Number byte data . The sending window continues to send paragraph by paragraph 4 Duan Hedi 5 Segment data , And when the second message is sent 5 After segment data , You can't send new data .
At this time , The first 2 The retransmission timer for segment has timed out , The first 2 Segment is retransmitted . After receiving these data , host B yes 501 Cumulative confirmation of previous data , And adjust the receiving window to 100.
The send window continues to move forward , And resize the window to 100 byte .A Continue sending page 6 Segment data ,B A confirmation message is sent after receiving it , And resize the window to 0.
After receiving the confirmation message ,A Send window forward , And resize to 0. here ,A Will start the duration timer , If B No message is sent to adjust the receiving window within the timing time , Or the message sent is lost ,A Zero window detection message will be sent .
B After receiving the detection message , It will be confirmed , And inform yourself of the size of the receiving window . If still 0 Words ,A The duration timer will restart ; And if not 0 Words ,A The size of the send window will be adjusted , Start transmitting message .