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
Scroll sideways to see the full diagram.
Both peers choose a starting number for bytes they send. Their numbers are independent.
Step 1 of 4The phone announces 100. The server has heard the phone.
Step 2 of 4The server announces 500 and asks the phone for 101 next. Predict what the phone should acknowledge.
Step 3 of 4The 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.
| Message | Information it carries |
|---|---|
| Phone sends SYN, sequence 100 | The phone proposes its starting number. |
| Server sends SYN-ACK, sequence 500, acknowledgment 101 | The server proposes its number and says the next number it expects from the phone. |
| Phone sends ACK, acknowledgment 501 | The 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.
Check yourself
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.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.