What is the TCP three-way handshake?
There are three blocks here, corresponding to three IP packets. This is the “TCP three-way handshake”. The goal of this process is to establish a connection.
Connection establishment is like a legal contract. Each party must agree to the contract, and have a copy of the other party’s agreement to the contract. The contract content could be thought of as
127.0.0.2shall transmit two byte streams between each other.
127.0.0.1shall send a byte stream from port
127.0.0.2shall send a byte stream from port
The first packet is the client requesting a connection. But the connection contract can’t be achieved with a single “open connection” packet. TCP works over IP, where there is no guaranteed delivery; thus the client cannot know that the server received the “open connection” packet. Also, the server might choose to deny the connection even if it receives the request!
The client wishes to know whether the the server has accepted the connection. This acceptance is called “acknowledgement” in TCP, and this is the second packet in the handshake: the server acknowledges the connection.
Doesn’t it seem like two packets are enough to establish the connection? A legal contract could work this way. But two packets are not enough, because the “connection contract” actually consists of a couple more facts:
The first byte in the byte stream from
127.0.0.1:56742shall have number
3112279261. The first byte in the byte stream from
127.0.0.2:12345shall have number
3504942089 are “initial sequence numbers”.
You can see them in the
An initial sequence number is chosen at random by its source host,
3112279261 at random
3504942089 at random.
Thus the full contract is not written by the client;
it is only known after the server responds.
This means the server now wants a response from the client,
acknowledging the server’s initial sequence number.
This is the third packet in the three-way handshake.
(Why do we have these random initial sequence numbers? I’ll cover that some other time.)
More by Jim
- A probabilistic pub quiz for nerds
- Time is running out to catch COVID-19
- The inception bar: a new phishing method
- The hacker hype cycle
- Project C-43: the lost origins of asymmetric crypto
- How Hacker News stays interesting
- My parents are Flat-Earthers
- The dots do matter: how to scam a Gmail user
- The sorry state of OpenSSL usability
- I hate telephones
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- Granddad died today
- Your syntax highlighter is wrong
Tagged . All content copyright James Fisher 2018. This post is not associated with my employer. Found an error? Edit this page.