I believe you have all encountered such a scenario:
Classmate Luffy call you, let you write down a bunch of mobile phone number, but your memory is not very good, you and Luffy agreed, at a maximum of only 4 numbers, Luffy read it again, if you hear the words he said repeat. Next: You: You are the most reported 4 a number, more than I remember AH. luffy:139 you: 139 (Luffy know you heard) luffy:7548 you: 7538 (obviously you heard wrong) Luffy: No, it's 7548 you: 7548 luffy:2669 you: 2669
Finally, the complete number you received is 139-7548-2669. 1. Sliding window
In the above scene, you can only accept 4 digits at a time, indicating that the size of your sliding window is 4. In the TCP protocol, there is also a sliding window, whose size indicates how many bytes of data are currently being received.
Each time TCP receives a message from each other, it checks the window size field, as shown in Figure 1.
Figure 1 There is a field in the TCP header--16-bit window size
Know the other side of the window size, you know how much data the other party can receive, the data byte ordinal is the value of the ACK in the TCP segment to the ACK + window size, that is [ack,ack+ window size) [A C K, a C K + window size] [ACK, ACK + Window size).
For example, you send a paragraph with a byte serial number of [400, 500]. The other side sent a TCP segment, ACK = 100, win = 400, which means that I have received the data from [500) and I can also receive data between the byte ordinal number [500, 600], as shown in Figure 2.
Figure 2 Sliding window
If the other side loopback a TCP segment, Ack =, win = 0, it means that I have received [400, 500) of the data, but I can not receive the data now, you will be sent later.
Fig. 3 The opposite side sends back a 0 size window, receiving the response
2. The purpose of sliding windows
Looking back at the example of the call given at the beginning of this article, why should you tell each other that you can only report 4 digits at a time? The reason is that your ability to accept is limited, not that you can't memorize a lot of numbers, just in the short term, you can't remember, you need a paragraph of memory (a paragraph of the data into the buffer).
Therefore, in TCP, the sliding window is to achieve flow control . If the other person sent the data too fast, the receiver is too late to receive (you are not anxious to remember), the receiver will need to notify each other, slowing the sending of data (Figure 3).
The special note is that when learning the sliding window, we assume that the network is infinitely good and does not have congestion . As long as you send the data, the other party will be able to receive.
Again explain the meaning of network congestion, it refers to the data you send stranded in the network, delay to reach the receiver. 3. Sliding window Simulation
Figure 4 Sliding window simulation
FIX: The last small figure in Figure 4 fixes the text, should be for "the sender received ack=41, win=10, know the other side want to receive the serial number of [41, 51) data" The sender received the message ack =, win = 10, know that the other side received the data before 33rd , now expect to receive [33, 43) data. The sender continuously sends 4 message Segments assuming a, B, C, D, carrying [33, 35), [35, 36], [36, 38], [38, 41] data. The receiver received the message segment A, C, but did not receive B and D, that is, only received [33, 35] and [36, 38) data. The receiver sends back a confirmation of message segment A: ACK = 10. The sender received an ACK = 10, and the other party expects to receive the [35, 45) data. It then sends a message segment E, which carries data of [41, 44]. The receiving party received the message segment B: [41, d:[38, and the receiver sent a confirmation to D: ACK = 10. ( This is a cumulative confirmation ) The sender received an ACK = 10, win = 41, and the other side expects to receive the data of the [51) number. ......
It is important to note that the receiver received the TCP message in the order is uncertain, is not necessarily received 35 before receiving 36, it may be received 36, 37, and then received 35. 4. Summarize understanding of the sliding window's working process sliding window for what purpose.
Next article, we have to grab a bag to analyze.