4.3.21 · HinglishComputer Networks

TCP flow control — sliding window, receive buffer

1,652 words8 min readRead in English

4.3.21 · Coding › Computer Networks


Flow control exist kyun karta hai?


Receive buffer kya hai?


Sender ka constraint first principles se derive karna

Chalo rule build karte hain, memorize nahi karte.

Step 1 — sender ke bytes ko naam do.

  • LastByteSent = highest byte number jo sender ne network mein push kiya hai.
  • LastByteAcked = highest byte number jo receiver ne acknowledge kiya hai.

Yeh do kyun? In-flight (unacknowledged) bytes exactly woh hain jo bheje gaye hain lekin abhi tak acked nahi hue:

Step 2 — receiver ka promise. Jab receiver ne rwnd advertise kiya, usne guarantee di ki uske paas utna free room hai. Toh sender ko yeh maintain karna chahiye:

Yeh exactly sahi kyun hai: har in-flight byte eventually receive buffer mein land karegi. Agar in-flight bytes ≤ free space hai, toh buffer unhe sab absorb kar sakta hai bina overflow ke. Q.E.D. — sliding-window rule bas yeh hai ki "in-flight ≤ advertised free space."


Isse sliding window kyun kehte hain

Figure — TCP flow control — sliding window, receive buffer

Worked Example 1 — basic accounting


Worked Example 2 — window ZERO ho jaata hai


Worked Example 3 — window scaling (16-bit limit)



Recall Feynman: 12-saal ke bacche ko explain karo

Imagine karo tum apne dost ke cup mein hose se paani daal rahe ho. Tumhara dost dheere dheere peeta hai. Har moment tumhara dost chillata hai "mere cup mein ITNI jagah baaki hai!" Tum utna hi daalte ho, zyada nahi — taaki cup kabhi overflow na ho. Jab cup bhar jaata hai, tumhara dost chillata hai "ZERO jagah!" aur tum daalana band kar dete ho. Tum thodi thodi der mein hose ko thapthapate rehte ho poochne ke liye "koi jagah abhi?" Jab tumhara dost kuch peeta hai aur chillata hai "okay, jagah hai!", tum phir daalana shuru karte ho. Woh cheekha hua number hai window, cup hai receive buffer, aur thapthapana hai zero-window probe.


Flashcards

TCP flow control kaunsi problem solve karta hai?
Ek fast sender ka slow receiver ke finite receive buffer ko overflow kar dena (yeh ek endpoint problem hai, network problem nahi).
Advertised receive window rwnd ka formula
rwnd = RcvBuffer − (LastByteRcvd − LastByteRead).
Core sliding-window inequality jo sender ko maanni chahiye
LastByteSent − LastByteAcked ≤ rwnd (in-flight bytes ≤ advertised free space).
Sender abhi kitne MORE bytes transmit kar sakta hai?
rwnd − (LastByteSent − LastByteAcked).
rwnd wire pe kahan carry hota hai?
Receiver ke bheje TCP segments ke 16-bit Window field mein.
rwnd ke 0 hone pe deadlock kya hai, aur uska fix?
Agar koi data flow nahi hota toh receiver window update nahi bhej paata; fix = sender periodic 1-byte zero-window probes bhejta hai taaki fresh advertisement mile.
rwnd aur cwnd mein farq?
rwnd receiver ke buffer ko protect karta hai (receiver set karta hai); cwnd network ko protect karta hai (sender estimate karta hai). Sender min(rwnd, cwnd) use karta hai.
Window scaling kyun zaroori hai aur yeh kaise kaam karta hai?
16-bit Window max 65535 bytes tak jaata hai, high bandwidth-delay links ke liye bahut chhota hai; Window Scale option field ko 2^s se multiply karta hai, handshake pe negotiate hota hai.
In-flight bytes ko rwnd se kyun subtract karte hain?
Woh bytes pehle se receive buffer mein reserved seats le chuke hain; woh advertised room ke against count hote hain.

Connections

Concept Map

can overrun

drains slowly

may overflow

receiver-driven brake

free space gives

advertised in

tells sender

bounded by

ACK moves left edge

distinct from

Fast sender

Slow receiver

Receiving app reads at own pace

Receive buffer RcvBuffer

Flow control

Receive window rwnd

Window field 16-bit

Rule LastByteSent minus LastByteAcked le rwnd

In-flight bytes

Sliding window

Congestion control cwnd