乐闻世界logo
搜索文章和话题

How does the sliding window mechanism of TCP flow control work?

2月21日 17:09

TCP Flow Control Mechanism Explained

TCP flow control is a key mechanism to prevent the sender from sending data too fast and causing the receiver's buffer overflow.

Sliding Window Mechanism

Window Size

  • Receive Window (rwnd): Available buffer size advertised by the receiver
  • Congestion Window (cwnd): Window size calculated by the sender based on network conditions
  • Actual Send Window: min(rwnd, cwnd), taking the smaller of the two

Working Principle

  1. Receiver Advertisement: Advertise current available receive window size in the window field of TCP segment
  2. Sender Adjustment: Sender adjusts sending rate based on receiver's window size
  3. Zero Window: When receiver buffer is full, advertise window size as 0
  4. Window Probe: Sender periodically sends zero window probe segments to query if receiver window is available

Flow Control Process

Normal Situation

  • When receiver has sufficient buffer, window size remains large
  • Sender can continuously send multiple segments
  • After receiver processes data, it updates window size and advertises to sender

Buffer Tension

  • When receiver buffer is nearly full, reduce window size
  • Sender correspondingly reduces sending rate
  • Avoid data loss and retransmission

Zero Window Handling

  • When receiver buffer is full, advertise window size as 0
  • Sender stops sending data but maintains connection
  • Periodically send zero window probe (1 byte data)
  • After receiver has space, update window size

Timing of Window Updates

  • After Receiving Data: Process data and release buffer space
  • After Application Layer Reads Data: After reading data from receive buffer
  • Zero Window Probe Response: Respond to sender's probe segment
  • What is the difference between flow control and congestion control?
  • Why do we need zero window probe mechanism?
  • How does sliding window affect TCP throughput?
标签:TCP