CoursesTCP to HTTPS, one request under a microscope

Puzzle 0 · 1 of 5

Why TCP starts with three messages

Follow the first exchange between a phone and a server. What has each side learned at every step?

All puzzles in this course

The problem

A phone knows a server address and can send packets to it. Both sides will send bytes, and each side chooses its own starting number. How do they agree on both starting numbers before exchanging application data in the ordinary case?

See it

TCP setup: the phone sends SYN 100, the server replies with SYN 500 and ACK 101, then the phone acknowledges 501. Phone Server SYN 100 SYN 500 · ACK 101 ACK 501

Scroll sideways to see the full diagram.

  1. Both peers choose a starting number for bytes they send. Their numbers are independent.

    Step 1 of 4
  2. The phone announces 100. The server has heard the phone.

    Step 2 of 4
  3. The server announces 500 and asks the phone for 101 next. Predict what the phone should acknowledge.

    Step 3 of 4
  4. The phone acknowledges 501. The server now knows its opening message made the return trip.

    Step 4 of 4

The building block

TCP gives the two apps a reliable, ordered byte stream in each direction. A sequence number identifies a position in one direction of that stream. The opening handshake is a setup exchange between the peers.

MessageInformation it carries
Phone sends SYN, sequence 100The phone proposes its starting number.
Server sends SYN-ACK, sequence 500, acknowledgment 101The server proposes its number and says the next number it expects from the phone.
Phone sends ACK, acknowledgment 501The phone says it received the server's opening number and expects 501.

SYN signals the start and consumes one position in each direction. ACK is an acknowledgment, which reports the next number expected from the other side. In this example, the first regular data sent by the phone starts at 101, and the server's data starts at 501.

After receiving the second message, the phone can acknowledge the server and treat the connection as established. The server ordinarily moves to that state after receiving the final valid ACK. The final acknowledgment may also carry data. If it is lost and no other valid acknowledgment arrives, the server still needs confirmation and can retransmit its SYN-ACK. The third message confirms the phone saw the server’s fresh SYN. A delayed duplicate SYN by itself cannot complete the connection. These exchanges synchronize the byte streams. They do not verify the server's identity for the application.

Go deeperCount both directions separately
If the server changes its initial number from 500 to 900, which acknowledgments change?

The phone now acknowledges 901. The server still acknowledges 101 because the phone's starting number did not change.

Back to the main puzzle

Check yourself

The third message is lost and nothing else arrives. What is the server missing?

Right. Keep track of what each peer has actually received.

Not quite. The server chose its own starting number before sending SYN-ACK. Re-read that part ↑

Not quite. The server already received that number in SYN. Re-read that part ↑

The server proposes 800. What does the phone acknowledge?

Not quite. SYN consumes a position. The acknowledgment says what is next. Re-read that part ↑

Right. The two sequence spaces are independent.

Not quite. The acknowledgment refers to bytes from the other peer. Re-read that part ↑

What has the phone established about the server after this exchange?

Right. Opening the byte stream answers a transport question.

Not quite. Establishment does not eliminate packet loss. Re-read that part ↑

Not quite. This exchange does not verify the application identity. Re-read that part ↑

Sources

What you now know

The TCP handshake exchanges starting byte numbers and confirms both directions. A peer that has received only the first two messages has different information from its peer.