The three-way handshake protocol is part of the Transport Layer in the OSI (Open Systems Interconnection) model. Specifically, it is used by the Transmission Control Protocol (TCP) to establish a reliable connection between a client and a server.
It involves three steps:
When a TCP connection is established, both the client and the server choose an initial sequence number (ISN). These ISNs are chosen randomly to minimize the risk of sequence number prediction attacks.
The client sends a TCP segment with the SYN flag set and its chosen ISN. Let’s assume the client’s ISN is x.
The server responds with a TCP segment that has both the SYN and ACK flags set. The server chooses its own ISN, let’s say y. The ACK flag acknowledges the client’s SYN segment by setting the acknowledgment number to x + 1 (the client’s ISN plus one).
The client sends a TCP segment with the ACK flag set, acknowledging the server’s SYN-ACK segment. The acknowledgment number is set to y + 1 (the server’s ISN plus one). The sequence number is set to x + 1 (the client’s ISN plus one), indicating that the client is ready to send data starting from this sequence number.
Client Server
| |
| ---- SYN, Seq = x ---------->|
| |
| <--- SYN, ACK, Seq = y, Ack = x + 1 ---> |
| |
| ---- ACK, Seq = x + 1, Ack = y + 1 ----> |
| |
More about tcp is in the RFC 793 in links section.
The above works in case of no data. If data is sent, the sequence number is incremented by the number of bytes sent…
Involves a 4 way handshake.