TCP control (flow control/window size)

TCP control (flow control, window size)

 In TCP communication, the sending side sends a segment, and when the receiving side receives the segment, it always returns an ACK response.

In the receiver's response, return the expected next sequence number (sequence number of received segment + 1).

in short,

Up to now, I have been able to receive it properly, so please send me the next segment. "

It means that · · ·

 Flow control in TCP is realized by window size. The window size determines how many segments can be sent at once. TCP performs flow control by controlling the number of segments sent and received at one time.

 In a little more detail, window size refers to the buffer size of the communication partner. Received data is temporarily stored in a buffer.

If the data transfer is fast, the buffer will fill up quickly and overflow. And the packet will be discarded.

In other words, even if data up to the window size is sent at once, the other party will not overflow.

 In TCP communication, when establishing a three-way handshake connection, in addition to the sequence number and acknowledgment number, the window size (the size of its own buffer) and MSS are also told to each other.

 From this taught window size and MSS, we can determine the number of segments that can be sent at once. TCP performs flow control by controlling the number of segments sent and received at one time.

First, I will explain flow control when the number of segments that can be sent at once is "1".

for example

window size = 1,000
MSS = 1,000

, the number of segments that can be sent at one time is "1".

 As you can see from the above figure, every time we send one segment, we do an acknowledgment. It must wait for an ACK response for each individual packet before sending the next segment.

With this, you can certainly deliver to the other party, but it takes too much time and overhead.

If you don't send more efficiently, it will take too much time.

 For efficient transmission, instead of waiting for an ACK response for each segment before sending the next segment, multiple segments can be sent at once without waiting for an ACK response.

sliding window

This section describes the interaction flow when sending multiple segments at once.

 At the time of establishing a three-way handshake connection, in addition to the sequence number and acknowledgment number, the window size (size of own buffer) and MSS are also told to each other.

For example, if the receiver's window size and MSS values ​​are

window size = 3,000
MSS = 1,000

The number of segments that can be sent at one time is "3".

 The sender is sending segments 1, 2, 3 in succession. When the sender receives the "ACK=4" response for packet 3, it will now send segments 4, 5, 6 in succession.
*Actually, it depends on the window size reported by the receiving side.

 Instead of waiting for an ACK response for each individual segment before sending the next segment, multiple segments are sent at once for efficiency. In this way, in TCP communication, flow control is performed by sending multiple segments at once without waiting for an ACK response.

 The number of segments that can be sent at once is determined by the window size. This window size is not always the same value. Increases or decreases depending on the buffer size of the destination.

 The receiving side's buffer size decreases as segments are received, and as the processing is completed, free space increases and the buffer size increases.

 The sender must then manage which segments to send and how many. Otherwise, you could send too many segments and overwhelm the receiver's buffer, and sending too few segments would be inefficient.

 Therefore, TCP uses a mechanism called a sliding window to manage which segment should be sent next and how much.