Original link: http://www.cnblogs.com/luoquan/p/4886345.html
TCP This protocol is widely used in the network, he is a connection-oriented reliable transport protocol. Since it is a reliable transport protocol, the data needs to be confirmed. There are 2 window mechanisms in the TCP protocol: one is a fixed window size, and the other is a sliding window. The size of this window is that we transmit several data at a time. All data frames are numbered sequentially, and the sender always maintains a send window during sending, only the frames falling within the sending window are allowed to be sent, and the receiver maintains a receive window, only the frames falling within the receiving window are allowed to be received. This allows for flow control by adjusting the size of the sender window and the receiver window.
TCP sliding window technology adjusts the data transfer between two hosts by dynamically changing the window size. Each TCP/IP host supports full-duplex data transfer, so TCP has two sliding windows: one for receiving data and the other for sending data. TCP uses a positive acknowledgment technique whose confirmation number refers to the next expected byte. assume that the sender device sends data at three packets each time, that is, the window size is 3. The sender sends three packets with a serial number of 1, 2, 3, and the receiving device successfully receives the packet and confirms it with the serial number 4. The sender device receives confirmation and continues to send data at window size 3. When the receiver device needs to reduce or increase network traffic, the window size can be reduced or increased, this example reduces the window size of 2, each time sending two packets. When the receiver device requires a window size of 0, it indicates that the receiver has received all the data, or the receiving application does not have time to read the data, requiring a pause to send. The sender receives a confirmation with a window number of 0 to stop the data transfer in this direction.
We can look at the following diagram to analyze the fixed window size what is the problem.
Here we can see that the size of the hypothetical window is 1, and only one data can be sent each time only the recipient confirms the data to send the 2nd data. We can see that the sender sends an ACK to the sender to confirm that the data is sent to each receiver. The next data can be transmitted only after receiving the confirmation data. So let's think about it. If the window is too small, then when the transmission of relatively large data need to constantly confirm the data, this time will cause a great delay. If the size of the window definition is too large. We assume that the sender sends 100 data at a time. However, the receiver can only process 50 of data. This will only confirm the 50 data at a time. The sender will send 100 data the next time, but only 50 data will be processed by the receiver. This avoids unnecessary data congestion on our links. So we introduced the sliding window mechanism, the size of the window is not fixed but according to the link between us the size of the bandwidth, this time the link does not support plug. Whether the receiver can handle so much data.
Let's see how the sliding window works. Let's take a look at the following pictures.
First, the first time the data is sent the window size is determined by the size of the link bandwidth. Let's assume that the size of the window at this time is 3. This time the receiving party will confirm the data after receiving the data and tell the sender what I want to reach next time. Here we see the ack=3 sent by the receiver (this is the answer confirmation for the sender to send sequence 2, the next time the receiver expects to receive a 3 sequence signal). This time the sender received this data will know that I first sent 3 data each other only received 2 . I knew that the 3rd data was not received. The next time you send it, start with the 3rd data. At this point, the window size becomes 2 .
This time the sender sends 2 data.
Seeing that the receiver sends an ACK of 5 means that the next time he wants to receive the data is 5, the sender will know that the 2 data I have just sent the other party received this time to start sending the 5th data.
This is the working mechanism of the sliding window, when the link is better or worse, the window will also change, not the first time after the negotiations will never change.
Sliding Window Protocol
The sliding window protocol is a kind of traffic control method used by TCP. This protocol allows the sender to continuously send multiple groupings before stopping and waiting for confirmation. Because the sender does not have to pause for confirmation every time a packet is sent, the protocol accelerates the transfer of data.
The sending window is only possible to slide forward if the receiving window is sliding forward (while also sending a confirmation).
The two ends of the window in accordance with the above laws and constantly sliding forward, so this protocol is called Sliding window protocol.
When both the Send window and the receive window are equal to 1 o'clock, the wait protocol is stopped.
The sliding window mechanism of TCP "go"