Data Transfer — ACKs, Resends and Waiting in Line
An early Manja Arena prototype sent kite positions over TCP. On good Wi-Fi it felt fine. On a crowded café network, kites froze for a moment and then leapt forward all at once. Nothing was broken: TCP was keeping exactly the promise it makes.
The rule
Every byte numbered, every gap resent, nothing skips the queue.
- Every byte numbered. Sequence numbers count bytes, not messages, so the receiver always knows exactly which bytes it holds.
- Every gap resent. The receiver's acknowledgment names the next byte it is waiting for. If no acknowledgment covers some data before a timer runs out, the retransmission timeout, the sender sends that data again. It resends sooner if it receives three duplicate acknowledgments: the receiver asking for the same missing byte again and again while later segments keep arriving. That early resend is called fast retransmit.
- Nothing skips the queue. TCP hands bytes to your program strictly in order. Segments that arrive after a gap wait in the receive buffer until the gap is filled. This is head-of-line blocking.
A plain acknowledgment can only say "I have everything before byte N". Selective acknowledgment (SACK), an option both sides agree to during the handshake, lets the receiver add "and I also hold these later blocks", so the sender resends only the hole instead of everything after it.
For lobby chat, all of this is exactly right: every line arrives, in the order it was typed. For kite positions it is poison. A position from 50 ms ago is worthless once a newer one exists, yet TCP makes the newer one wait until the old one has been resent, which costs at least a round trip.
The shortcut
Track two things: what has arrived and what the program may read. The program may read only up to the first gap, and the acknowledgment number points at that same spot: the first missing byte.
Send
The server sends five 100-byte segments: bytes 0–99, 100–199, 200–299, 300–399 and 400–499.
Drills
Answer fast — trust the rule.
A receiver holds bytes 0–499 with no gaps. What acknowledgment number does it send?
Bytes 0–99 and 200–299 have arrived, but 100–199 was lost. What can the program read right now?
What does selective acknowledgment (SACK) add to plain acknowledgments?
A sender receives three duplicate acknowledgments, all saying 100. What does it do?
Why does head-of-line blocking hurt kite positions more than lobby chat?
Remember
- Every byte numbered, every gap resent, nothing skips the queue.
- The program can read up to the first gap, and the acknowledgment points at it.
- Trap: sending state that is replaced every tick over TCP. One loss freezes everything behind it.
