TCP three-way handshake
How two hosts agree to talk, and how they stop
TCP opens a connection with three messages and closes it with four. Sequence numbers keep both sides in step.
Three-way handshake
Why three messages
- The server learns that the client can send.
- The client learns that the server can send and receive.
- The server learns that the client can receive.
Two is not enough
An old duplicate SYN can arrive late. With two messages, the server opens a useless connection for it.
State changes
Flags
| Flag | Job | In handshake |
|---|---|---|
| SYN | Start a connection | steps 1, 2 |
| ACK | Confirm receipt | steps 2, 3 |
| FIN | Stop sending | not used |
| RST | Reset at once | on error |