The TCP 3-Way Handshake: What It Is and Why It's Important

What is TCP :

TCP (Transmission Control Protocol) is a communication protocol used in computer networks to ensure reliable, ordered, and error-checked delivery of data between devices. TCP is like a system that makes sure your data gets delivered safely when you're using the internet. Imagine you’re sending a letter to a friend.

  • Reliability: TCP ensures that all the data sent over a network reaches the destination accurately. If any packet (a piece of data) gets lost during transmission, TCP will notice the problem and resend it. It ensures there are no missing pieces.

  • Ordered Delivery: Sometimes, the data is broken into smaller chunks called "packets" to send over the network. These packets might not arrive in the same order they were sent. TCP makes sure that the packets are re-assembled in the right order when they reach the destination, even if they came in out of order.

    For example, imagine sending a package with 3 boxes (packets). One box might arrive first, then the second, and finally the third. TCP will make sure the receiver gets them in the order you sent, and if any are missing, it will ask for them again.

  • 3-Way Handshake in TCP:

    • Step 1 - SYN (Synchronize):
      The sender sends a special packet called "SYN" (Synchronize) to the receiver. This packet tells the receiver, "I want to start a communication with you."

    • Step 2 - SYN-ACK (Synchronize-Acknowledge):
      The receiver responds by sending back a packet called "SYN-ACK." It acknowledges the sender's request (with the "ACK" part), and also tells the sender, "I'm ready, and I also want to communicate."

    • Step 3 - ACK (Acknowledge):
      Finally, the sender sends a packet called "ACK" to confirm that it received the receiver’s "SYN-ACK." Now both sides are ready, and the connection is fully established.

  • Once the 3-way handshake is complete, the two devices can begin sending and receiving data reliably.

Why It's Called a "3-Way Handshake

The name comes from the three messages exchanged between the two devices during the setup process:

  • SYN (Sender to Receiver)

  • SYN-ACK (Receiver to Sender)

  • ACK (Sender to Receiver)

How the Internet Says 'Hello': A Visual Guide to TCP Handshake

Step 1: The Client Initiates

Imagine you're trying to access a website. Your device (the client) sends a message to the server hosting the website. This message, called a SYN packet, is like saying, "Hello, server! Are you listening?

Step 2: The Server Acknowledges

The server receives the SYN packet and responds with a SYN-ACK packet. This is like the server saying, "Yes, I'm here! I'm ready to talk. Here's my identification.

Step 3: The Client Confirms

Finally, the client sends an ACK packet to the server, confirming the connection. This is like the client saying, "Great, let's start chatting!

Reliable Connections in TCP: How Sequence Numbers and ACKs work.

Imagine you're sending letters to a friend to share a story, and you want to make sure every part of the story arrives in the correct order without any missing pages. This process is similar to how sequence numbers and ACKs (acknowledgments) work in TCP for reliable data transmission.

  1. Breaking the Story into Pages:
    You write your story on several pages (data packets). Each page is numbered so your friend knows the correct order (sequence numbers).

  2. Sending the Pages:
    You send one page at a time through the mail. Each page is like a TCP packet containing part of the data.

  3. Receiving Confirmation (ACKs):
    After your friend receives each page, they write back saying, "I got page 1," "I got page 2," and so on. These responses are the ACKs in TCP.

  4. Handling Lost Pages:
    If one page gets lost in the mail (packet loss), your friend notices it's missing (e.g., they received pages 1, 2, and 4 but not 3). They ask, "Can you resend page 3?" TCP handles this by resending the missing packet.

  5. Complete Story Assembled:
    Once all pages are received and acknowledged, your friend has the complete story in the correct order, ensuring no part is missing or out of sequence.

  • Sequence Numbers: The page numbers you write on each page. They ensure the story (data) is reconstructed in the correct order.

  • ACKs (Acknowledgments): Your friend’s response confirming they received each page.

  • Packet Loss Recovery: When a page is lost, your friend asks for a resend, and you send it again.

  • Reliable Communication: You and your friend know the entire story is exchanged without errors or missing parts.

0
Subscribe to my newsletter

Read articles from Maulik Gajipara 🏌️ directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Maulik Gajipara 🏌️
Maulik Gajipara 🏌️