What is the TCP flow control?

Before start discussing TCP flow control, it’s worth describing what is the flow control functionality in computer networks.  When two network hosts start communicating with each other, one sends packets, and the other receives them.  Both may have different hosting hardware, software design, and processing speed.  If the receiver is fast enough to consume messages at a higher rate than generated by the sender,  all works well.

But what will happen if the receiver consumes slower than the sender produces?  The messages will keep adding to the receiver’s queue. After some time, messages will start dropping once the receiver queue is full. To overcome a fast sender and a slow receiver problem, in Computer networks, there is a concept known as flow control.

What is tcp flow control
What is the TCP flow control?
  •              Slow sender speedy receiver – No Flow Control required,
              Fast sender, slow receiver – Flow control is required.

      In the above diagram, there is a slow receiver and a fast sender.  Let’s understand how the messages will be overflown after a certain period of time.

  • The sender is sending messages at the rate of 10 messages per second while the receiver is receiving at the rate of 5 messages per second.
  • When a sender sends a message, the network enqueues messages in the receiver queue.
  • Once a message is read by the user application. The message is clear from the line, and now again, one buffer space adds to the free space.
  • With the mentioned speed for the sender and receiver, the receiver queue will keep shortening at the pace of 5 every second.
  • Finally, after 40 seconds, there will be no space remaining for incoming messages, and messages will start dropping.

Why is TCP flow control required?

TCP is an example of a transport layer protocol as per the OSI reference model. It provides reliable and sequenced delivery of messages.  Because of reliable delivery, TCP retries to send a lost segment if a packet is lost due to a slow receiver. If no flow control, TCP will keep resending again and again, and the situation will get worse over the network.

With the flow control, during the communication TCP receiver keep sending the available space capacity for the incoming messages to the sender. The sender updates the space information and reduces the message sending rate. The space is known as the receiver window size.

How TCP does the flow control?

For implementing flow control, the sender should know how much free space is available on the receiver, before sending further messages. In an earlier TCP header tutorial, we have described various protocol parameters. One parameter is the window size. In each TCP segment, both ends add their own window size in the header.

At the time of connection setup, the window size is the maximum capacity available. During packet transfer, the window size keeps updating. When a TCP end, can not accept any more messages, the window size is set to zero.
When the sender receives a window size zero,  should not try to send any further messages. Till it gets again a message with a window size of nonzero.

Flow control and TCP user:

Till now all discussion was for the TCP layer. Here we will discuss the traffic source for TCP, which is the user of the layer.

Difference Between Flow Control and Congestion Control:

The flow control is between end to end.  While congestion control is a node between the path from two nodes. For example, a router between two communicating nodes may get congested.

How does a TCP application know when to stop?

The purpose of flow control is to let the sender know that the receiver is slower.  For that, a sender application should be informed in case of a slow receiver. Generally, the TCP module informs the sender, while sending data.