Bird
Raised Fist0
Computer Networksknowledge~6 mins

TCP flow control (sliding window) in Computer Networks - Full Explanation

Choose your learning style10 modes available
Introduction
Imagine sending a long letter through a small mailbox. If you send too many pages at once, the mailbox overflows and pages get lost. TCP flow control solves this problem by managing how much data is sent before waiting for confirmation.
Explanation
Purpose of Flow Control
Flow control prevents the sender from overwhelming the receiver with too much data at once. It ensures the receiver can process incoming data without losing any. This keeps communication smooth and reliable.
Flow control balances data sending speed to match the receiver's ability to handle it.
Sliding Window Mechanism
The sliding window is a range of data packets the sender can send without waiting for an acknowledgment. As the receiver confirms receipt, the window slides forward, allowing more data to be sent. This keeps data flowing efficiently.
The sliding window lets the sender send multiple packets before needing confirmation, improving speed.
Window Size
The window size is the number of bytes the sender can send before stopping to wait for an acknowledgment. The receiver tells the sender its available buffer size, which sets the window size. This size can change dynamically during communication.
Window size controls how much data can be sent at once and adapts to the receiver's capacity.
Acknowledgments and Window Sliding
When the receiver gets data, it sends an acknowledgment with the next expected byte number. This moves the window forward, allowing the sender to send new data. If acknowledgments are delayed, the sender waits, preventing overload.
Acknowledgments move the window forward, signaling the sender to send more data.
Real World Analogy

Imagine a conveyor belt delivering boxes to a worker. The worker can only handle a few boxes at a time. The belt stops when the worker is full and starts again when space is freed. This keeps the worker from being overwhelmed.

Purpose of Flow Control → Worker's limit on how many boxes they can handle at once
Sliding Window Mechanism → The length of the conveyor belt section delivering boxes before stopping
Window Size → The number of boxes the worker can hold before needing to process them
Acknowledgments and Window Sliding → Worker signaling the belt to move more boxes after processing some
Diagram
Diagram
Sender Side Window:
┌─────────────────────────────┐
│[Data 1][Data 2][Data 3][Data 4][Data 5]│
└─────────────────────────────┘
       ↓
Receiver acknowledges Data 1 and Data 2

Window slides forward:
┌─────────────────────────────┐
│       [Data 3][Data 4][Data 5][Data 6][Data 7]│
└─────────────────────────────┘
This diagram shows how the sender's sliding window moves forward as the receiver acknowledges received data.
Key Facts
Flow Control → A method to prevent the sender from overwhelming the receiver with too much data.
Sliding Window → A range of data bytes the sender can transmit before needing acknowledgment.
Window Size → The maximum number of bytes the sender can send without waiting for acknowledgment.
Acknowledgment → A message from the receiver indicating which data bytes have been received.
Common Confusions
Believing flow control is the same as congestion control.
Believing flow control is the same as congestion control. Flow control manages data rate between sender and receiver to prevent overflow, while congestion control manages network traffic to avoid overall network overload.
Thinking the window size is fixed and never changes.
Thinking the window size is fixed and never changes. The window size can change dynamically based on the receiver's available buffer space.
Summary
TCP flow control uses a sliding window to manage how much data the sender can transmit before waiting for acknowledgment.
The window size adapts to the receiver's capacity to process data, preventing overload.
Acknowledgments from the receiver move the window forward, allowing continuous and reliable data flow.

Practice

(1/5)
1. What is the main purpose of the sliding window in TCP flow control?
easy
A. To control the amount of data sent before receiving an acknowledgment
B. To encrypt data during transmission
C. To assign IP addresses to devices
D. To route packets between networks

Solution

  1. Step 1: Understand the role of sliding window in TCP

    The sliding window limits how much data the sender can transmit before waiting for an acknowledgment from the receiver.
  2. Step 2: Identify the purpose among options

    Only To control the amount of data sent before receiving an acknowledgment describes controlling data flow using acknowledgments, which matches the sliding window's purpose.
  3. Final Answer:

    To control the amount of data sent before receiving an acknowledgment -> Option A
  4. Quick Check:

    Sliding window controls data flow = To control the amount of data sent before receiving an acknowledgment [OK]
Hint: Sliding window limits unacknowledged data sent [OK]
Common Mistakes:
  • Confusing flow control with encryption
  • Mixing routing with flow control
  • Thinking sliding window assigns IPs
2. Which of the following correctly describes the sliding window size in TCP?
easy
A. It is fixed and never changes during the connection
B. It is set by the IP address of the sender
C. It is always equal to the maximum segment size (MSS)
D. It increases or decreases based on acknowledgments received

Solution

  1. Step 1: Recall how sliding window size behaves

    The window size changes dynamically as acknowledgments arrive, allowing the sender to send more data.
  2. Step 2: Match behavior to options

    It increases or decreases based on acknowledgments received correctly states the window size adjusts based on acknowledgments, unlike fixed size or unrelated factors.
  3. Final Answer:

    It increases or decreases based on acknowledgments received -> Option D
  4. Quick Check:

    Window size changes with ACKs = It increases or decreases based on acknowledgments received [OK]
Hint: Window size changes with ACKs, not fixed [OK]
Common Mistakes:
  • Assuming window size is fixed
  • Confusing window size with MSS
  • Linking window size to IP address
3. Consider a TCP connection with a window size of 4 segments. The sender has sent segments 1 to 4. The receiver acknowledges segment 2. Which segments can the sender send next?
medium
A. Segments 5, 6, and 7
B. Segments 3 and 4 again
C. Segments 5 and 6
D. No new segments until all are acknowledged

Solution

  1. Step 1: Understand sliding window movement after ACK

    When segment 2 is acknowledged, the window slides forward, allowing sending of new segments beyond 4.
  2. Step 2: Calculate which segments fit in the window

    Window size is 4, segments 1 and 2 acknowledged, so segments 3 and 4 are still unacknowledged. The sender can send segments 5 and 6 to fill the window.
  3. Final Answer:

    Segments 5 and 6 -> Option C
  4. Quick Check:

    ACK 2 slides window, send next 2 segments = Segments 5 and 6 [OK]
Hint: ACK moves window; send new segments within window size [OK]
Common Mistakes:
  • Resending unacknowledged segments unnecessarily
  • Sending more segments than window size allows
  • Waiting for all segments to be acknowledged
4. A TCP sender has a window size of 3 segments and has sent segments 1, 2, and 3. The receiver sends an acknowledgment for segment 1 only. The sender mistakenly sends segment 4 and 5 immediately. What is the problem with this behavior?
medium
A. It violates the sliding window limit and may cause congestion
B. It improves throughput by sending more data
C. It is correct because ACK 1 means all previous segments are received
D. It causes the receiver to close the connection

Solution

  1. Step 1: Analyze window size and ACK received

    The window size is 3, and only segment 1 is acknowledged, so segments 2 and 3 are still unacknowledged.
  2. Step 2: Identify why sending segments 4 and 5 is wrong

    Sending segments 4 and 5 exceeds the allowed window size, risking congestion and data loss.
  3. Final Answer:

    It violates the sliding window limit and may cause congestion -> Option A
  4. Quick Check:

    Sending beyond window size causes issues = It violates the sliding window limit and may cause congestion [OK]
Hint: Don't send beyond window size before ACKs arrive [OK]
Common Mistakes:
  • Assuming ACK 1 means all segments received
  • Ignoring window size limits
  • Thinking sending more data always helps
5. In a TCP connection, the sender's window size is 5 segments. The receiver's buffer can only hold 3 segments. How should the sliding window mechanism adapt to prevent buffer overflow?
hard
A. The sender should keep sending 5 segments regardless
B. The sender should reduce the window size to 3 segments
C. The receiver should increase its buffer size to 5 segments
D. The sender should stop sending any segments

Solution

  1. Step 1: Understand receiver buffer limits

    The receiver can only hold 3 segments, so sending more than 3 risks overflow and data loss.
  2. Step 2: Adjust sender window size accordingly

    The sliding window size must match or be less than the receiver's buffer to avoid overflow, so the sender should reduce its window size to 3.
  3. Final Answer:

    The sender should reduce the window size to 3 segments -> Option B
  4. Quick Check:

    Sender window ≤ receiver buffer to prevent overflow = The sender should reduce the window size to 3 segments [OK]
Hint: Match sender window to receiver buffer size [OK]
Common Mistakes:
  • Ignoring receiver buffer size
  • Assuming receiver buffer can always expand
  • Stopping sending completely without reason
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard