TCP - Three-way handshake
Certainly! The TCP three-way handshake is a method used to establish a connection between a client and a server in the Transmission Control Protocol (TCP) segment of the Internet Protocol Suite. This handshake ensures both sides are ready for data transmission and establishes parameters that will remain in place for the duration of the connection.
Here's a step-by-step breakdown:
-
SYN (Synchronize Sequence Numbers)
- The client wants to establish a connection with a server, so it sends a segment with the SYN flag set. This segment also specifies an initial sequence number (let's say
x
). - This sequence number doesn't have to be 0; it's typically a random number to add security against certain types of attacks (like sequence number prediction).
- The client wants to establish a connection with a server, so it sends a segment with the SYN flag set. This segment also specifies an initial sequence number (let's say
-
SYN + ACK (Synchronize and Acknowledge)
- Upon receiving the SYN segment, the server replies with a segment that has both the SYN and ACK flags set.
- The acknowledgment number is set to one more than the received initial sequence number, i.e.,
x + 1
. - The server also selects its own initial sequence number for the data it will send to the client. Let's call this number
y
.
-
ACK (Acknowledge)
- The client sends an ACK segment back to the server.
- The sequence number is
x + 1
(because it's continuing from the last sequence number it used). - The acknowledgment number will be
y + 1
to acknowledge the server's SYN.
To summarize the sequence and acknowledgment numbers:
- Client -> Server: SYN with Sequence Number =
x
- Server -> Client: SYN + ACK with Sequence Number =
y
and Acknowledgment Number =x + 1
- Client -> Server: ACK with Sequence Number =
x + 1
and Acknowledgment Number =y + 1
After this handshake, both sides have agreed on the initial sequence numbers, and they can begin exchanging data.
As data segments are exchanged:
- The sequence number for each side will increase by the number of bytes of data sent.
- The acknowledgment number sent by each side will always be the next expected sequence number from the other side, which is essentially the last correctly received sequence number plus the number of bytes received.
This system of sequence and acknowledgment numbers is essential for ensuring reliable data transfer in TCP, allowing it to detect and retransmit missing or out-of-order segments.
For more information about the various aspects of this exchange, take a look at the following notes:
- TCP SYN timeout
- TCP - factors affecting segment size
- TCP phantom byte
- TCP MSS and window size
- MTU - MSS and Jumbo Frames
Links
https://networklessons.com/cisco/ccna-routing-switching/tcp-window-size-scaling/ https://networklessons.com/cisco/ccna-routing-switching/introduction-to-tcp-and-udp/