CoursesTCP to HTTPS, one request under a microscope

Puzzle 1 · 2 of 5

Where do the missing bytes go?

Drop one range of bytes while a later range arrives. Predict what the receiver reports and what the application can read.

All puzzles in this course

The problem

The phone sends three blocks of four bytes. They arrive as first, third, then second. Can the receiving app read the third block as soon as it arrives?

See it

Where do the missing bytes go? 101–104 109–112 waits 105–108 returns Next: 113

Scroll sideways to see the full diagram.

  1. The receiver accepts the first four bytes and expects 105.

    Step 1 of 4
  2. The third range arrives while bytes 105 to 108 are missing.

    Step 2 of 4
  3. The missing range arrives and fills the hole.

    Step 3 of 4
  4. If the later range was kept, the next expected byte advances to 113.

    Step 4 of 4

The building block

A cumulative acknowledgment reports the next byte needed to extend the contiguous prefix. Suppose the first byte has sequence number 101 and all three blocks are four bytes long.

Received byte positionsNext number expectedWhat TCP can make available in order
101–104105101–104
109–112 arrives early105Still only 101–104
Missing 105–108 finally arrives113Now 101–112, if the later bytes were kept

The receiver may buffer bytes that arrived ahead of a gap. It can still report 105, even though it has seen later bytes. The sender can send missing bytes again. When the gap closes, the acknowledgment can jump over the already buffered bytes.

TCP presents a continuous byte stream to the application. The app may read twelve bytes through one read or several, depending on when data is available and how much it asks for. The application has to understand its own message boundaries. It can't assume that one network segment equals one read or one complete message.

Go deeperLater data is useful without advancing the main acknowledgment
If the receiver tells the sender separately that it kept bytes 109–112, does the cumulative acknowledgment change?

It still reports 105. TCP selective acknowledgments can describe received ranges without claiming that the earlier gap is filled.

Back to the main puzzle

Check yourself

The receiver has bytes 101–104 and 109–112. What cumulative acknowledgment can it send?

Not quite. The value names the missing position rather than the latest arrival. Re-read that part ↑

Not quite. The cumulative value cannot cross a gap. Re-read that part ↑

Right. Find the first hole after the contiguous prefix.

Why can the app be waiting even while TCP has received new bytes?

Not quite. Reads can use an existing connection. Re-read that part ↑

Right. Ordered application delivery and network arrival order can differ.

Not quite. Contiguous bytes can be delivered before the connection closes. Re-read that part ↑

One application message covers bytes 101–112. The app first gets four bytes. What should it do?

Not quite. A read ending says nothing about the boundary of the application message. Re-read that part ↑

Not quite. TCP does not preserve application message boundaries. Re-read that part ↑

Right. Message boundaries belong to the next layer.

Sources

What you now know

A cumulative acknowledgment advances only across a contiguous prefix. Later bytes may wait while the receiver is missing earlier bytes.