Connection Establishment
Connection Establishment in TCP (3-Way Handshake) – Fully Explained
When two devices (like your computer and a web server) want to communicate over *TCP, they first perform a *3-way handshake to establish a reliable connection. Think of it like two people agreeing to start a phone call:
- “Hello, are you there?” (SYN)
- “Yes, I’m here! Are you ready?” (SYN-ACK)
- “Yes, let’s talk!” (ACK)
Now, the connection is open, and data can flow securely.
Detailed Step-by-Step Breakdown
1. SYN (Synchronize) – “Can we talk?”
- The client (your computer) sends a SYN packet to the server.
- This packet contains:
- A random sequence number (e.g., Seq=100) to start tracking data order.
- The SYN flag (set to 1) indicating a connection request.
- *Meaning: *”Hey server, I want to connect. My starting sequence number is 100.”
2. SYN-ACK (Synchronize-Acknowledge) – “I’m ready, are you?”
- The server responds with:
- Its own random sequence number (e.g., Seq=300).
- An ACK (Acknowledgment) = client’s Seq + 1 (101).
- Both SYN and ACK flags set (SYN=1, ACK=1).
- *Meaning: *”Got your request! My starting sequence number is 300, and I acknowledge your Seq=100. Are you ready?”
3. ACK (Acknowledgment) – “Yes, let’s start!”
- The client sends a final ACK packet:
- Acknowledgment number = server’s Seq + 1 (301).
- The ACK flag is set (ACK=1).
- *Meaning: *”Got your response! Let’s start exchanging data.”
Now, the TCP connection is fully established, and data transfer begins.
Why the 3-Way Handshake?
✔ Synchronizes sequence numbers (so data arrives in order).
✔ Ensures both sides are ready (no wasted resources).
✔ Prevents fake connections (only legitimate requests proceed).
Real-Life Example (Phone Call Analogy)
- You call a friend → “Hey, can we talk?” (SYN)
- Friend answers → “Sure! Can you hear me?” (SYN-ACK)
- You confirm → “Yes, let’s chat!” (ACK)
- Now you talk freely (data transfer).
What Happens If the Handshake Fails?
- If SYN is lost → Client retries after timeout.
- If SYN-ACK is lost → Server waits, then resets the connection.
- If ACK is lost → Server may keep waiting (but modern TCP has timeouts).
Key Takeaways
- The 3-way handshake ensures a reliable connection.
- SYN starts the process, SYN-ACK confirms, ACK finalizes.
- Without it, TCP wouldn’t be as trustworthy.
18 Comments