Demystifying TCP Three-Way Handshake: A Beginner's Guide

ยท

3 min read

In this article, we will try to understand the TCP 3-way handshake in very simple words. TCP 3-way handshake is nothing but the start of a conversation between two computers talking to each other.

So how do computers manage to communicate with each other across the vast internet? It's a bit like making a phone call or talking to a friend on a walkie-talkie. Just like you and your friend need to agree on when to start chatting, computers follow a similar process called the "TCP three-way handshake" before they can exchange data.

Let's dive a little deeper into this process:

Step 1: "Hey, Are You There?" (SYN)

Imagine you want to talk to your friend using a walkie-talkie. Before you start sharing exciting news, you need to make sure your friend is listening. So, you press the button and say, "Hey, are you there?" This is like the first step of the TCP handshake.

In computer terms, this step is called "SYN" (Synchronize). Your computer sends a TCP packet with a "SYN" flag set to 1, which means it wants to initiate a connection. This packet also includes a sequence number (SEQ), which is like a unique identifier for the conversation. It's like sending a letter with a specific code on it to your friend.

Step 2: "Yes, I'm Here!" (SYN-ACK)

Your friend hears your question and thinks, "Sure, I'm here, and I'm ready to listen." So, they press their walkie-talkie button and respond, "Yes, I'm here!" This is the second step of the TCP handshake.

In computer language, this step is also a "SYN" (Synchronize) message, but it's combined with an "ACK" (Acknowledgment). The receiving computer sends back a TCP packet with both "SYN" and "ACK" flags set to 1. This means it acknowledges your request to connect and also wants to initiate a connection back to your computer. It's like your friend saying, "I got your message, and I'm here too!"

This response packet also includes its own unique sequence number. Now both computers have sequence numbers to keep track of the data they will exchange.

Step 3: "Let's Start Talking" (ACK)

Now that both you and your friend know that you're ready to chat, you can start sharing your stories. You unmute your walkie-talkies, and the conversation flows. This is just like the final step of the TCP handshake.

In computer terms, this step is an "ACK" (Acknowledgment) message. Both computers send TCP packets with the "ACK" flag set to 1. This means they've received the acknowledgement from the other side and are ready to exchange data. They've agreed to start talking and sharing information.

And just like that, the TCP three-way handshake is complete! It's like a friendly introduction before computers can have a proper conversation. It ensures that both computers are on the same page, have exchanged sequence numbers, and are ready to share information securely.

ย