Skip to main content

Command Palette

Search for a command to run...

TCP Working: 3-Way Handshake & Reliable Communication

Published
3 min read

What is TCP and why it is needed?

Imagine you’re sending a long handwritten letter through the post:

  • You want all pages.

  • In the right order.

  • With nothing missing or duplicated.

but the internet itself is unreliable:

  • Data can get lost.

  • Data can arrive out of order.

  • Data can get duplicated.

  • Data can get corrupted.

To solve all these TCP(Transmission Control Protocol) is required.

Think of it like a rulebook computers follow to send data safely and correctly over the internet.

Problems TCP is designed to solve

  • Data loss → Some packets just disappear mid-way.

  • Wrong order → Packet 5 arrives before packet 2.

  • Duplicate packets → Same data arrives twice.

  • Overloading the receiver → Sender sends too fast → receiver crashes.

  • No confirmation → Sender has no idea if data arrived or not.

What is the TCP 3-Way Handshake

Before sending actual data, TCP first does a connection setup.

Think of it like a phone call :

  1. Can you hear me?

  2. Yes, I can hear you.

  3. Okay, let’s talk.

That’s the 3-Way Handshake.

SYN → SYN-ACK → ACK

Step 1: SYN (Client → Server)

Client says:

“Hey server, I want to talk. Are you there?”

  • SYN = Synchronize

  • Client also sends a starting number (sequence number)

Step 2: SYN-ACK (Server → Client)

Server replies:

“Yes, I’m here. I heard you. Are you ready?”

  • SYN: Server sends its own starting number

  • ACK: Server confirms client’s number

Step 3: ACK (Client → Server)

Client replies:

“Yes, I’m ready too.”

  • Connection is now officially open

  • Both sides agree on starting points

Now data transfer can begin.

How data transfer works in TCP

Once the connection is open, data is split into small pieces called segments (not sent as one big chunk).

Each segment has a number

This number tells:

  • Where it belongs

  • What comes before & after

Receiver sends ACKs, After receiving data, receiver says:

“Got segment #5 ”

Missing data is resent, If segment #6 doesn’t arrive:

  • Sender resends only #6

  • Not everything again

This is smart and efficient.

How TCP ensures reliability, order, and correctness

Reliability

  • Every segment must be acknowledged

  • If no ACK → resend

Correct order

  • Sequence numbers keep data in order

  • Receiver rearranges if needed

No duplication

  • Duplicate numbers → ignored

Flow control

  • Receiver tells sender:

“Slow down, I’m busy”

Congestion control

  • TCP detects network traffic

  • Automatically adjusts speed

How a TCP connection is closed

Think:

“I’m done talking.”
“Okay, me too.”
“Bye.”
“Bye.”

  1. Client sends FIN

    • “I’m done sending data”
  2. Server sends ACK

    • “Got it”
  3. Server sends FIN

    • “I’m also done”
  4. Client sends ACK

    • “Confirmed”

Connection closed cleanly.

Conclusion

TCP makes sure data between a client and server is delivered completely, in the correct order, and without guessing. From connection setup to safe data transfer and clean shutdown, TCP handles all the mess so applications can work reliably.

More from this blog

manojonweb

14 posts