Understanding the Three-Way Handshake in TCP/IP

The three-way handshake is a process used in the TCP/IP network protocol to establish a reliable connection between a client and a server. This handshake ensures that both parties are ready to transmit and receive data. Here’s a step-by-step explanation with an example:

Steps in the Three-Way Handshake

  1. SYN (Synchronize):
    • The client sends a TCP packet to the server with the SYN (synchronize) flag set. This packet contains an initial sequence number (ISN), which is a random value chosen by the client.
    Example: The client (Client A) wants to connect to the server (Server B).
    • Client A sends a SYN packet to Server B with an ISN of 1000.
  2. SYN-ACK (Synchronize-Acknowledge):
    • The server responds to the client with a TCP packet that has both the SYN and ACK (acknowledge) flags set. The server’s packet includes its own ISN and an acknowledgment number, which is the client’s ISN plus 1.
    Example: Server B receives the SYN packet and responds.
    • Server B sends a SYN-ACK packet to Client A with an ISN of 2000 and an acknowledgment number of 1001.
  3. ACK (Acknowledge):
    • The client sends an ACK packet back to the server. This packet has the ACK flag set and includes an acknowledgment number, which is the server’s ISN plus 1.
    Example: Client A receives the SYN-ACK packet and responds.
    • Client A sends an ACK packet to Server B with an acknowledgment number of 2001.

Detailed Example

Step 1: Client Sends SYN

  • Client A → Server B:
    • Source Port: 12345
    • Destination Port: 80
    • Flags: SYN
    • Sequence Number: 1000

Step 2: Server Sends SYN-ACK

  • Server B → Client A:
    • Source Port: 80
    • Destination Port: 12345
    • Flags: SYN, ACK
    • Sequence Number: 2000
    • Acknowledgment Number: 1001

Step 3: Client Sends ACK

  • Client A → Server B:
    • Source Port: 12345
    • Destination Port: 80
    • Flags: ACK
    • Sequence Number: 1001
    • Acknowledgment Number: 2001

Once this handshake is complete, a TCP connection is established, and data can be transmitted between the client and server.

Visualization of the Three-Way Handshake

Client A                  Server B
| |
| --- SYN (Seq=1000) ---> |
| |
| <-- SYN/ACK (Seq=2000, Ack=1001) -- |
| |
| --- ACK (Ack=2001) ---> |
| |

This process ensures that both parties agree on the initial sequence numbers and are ready to start the data transmission phase.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top