TCP Working: 3-Way Handshake & Reliable Communication

Search for a command to run...

No comments yet. Be the first to comment.
Comeing soon

In the previous blog of this JavaScript series, we explored JavaScript Operators: The Basics You Need to Know and learned how operators help us perform calculations, comparisons, and logical checks. B

In the previous blog of this JavaScript series, we learned about Variables and Data Types — how JavaScript stores information. Now the next question is: How do we actually work with those values? Th

If you're starting your JavaScript journey, one of the first concepts you'll encounter is Variables and Data Types. They are the foundation of everything in programming — from storing a user's name to

JavaScript Promises are one of the most misunderstood yet essential features in modern JavaScript development. Most articles explain the syntax. Very few explain: Why Promises exist How they actuall

Subhrangsu
18 posts
Imagine you walk into a shop, but before the shopkeeper starts serving you, you first greet each other and agree you’re ready to talk. Networking works in a similar way.
When two computers want to talk reliably over a network, they use a protocol called TCP (Transmission Control Protocol) to make sure both sides are ready and that messages won’t get lost, arrive out of order, or get corrupted along the way. (TechTarget)
At a high level, TCP is a protocol that helps two computers communicate reliably. It’s used for things like:
TCP ensures that the data you send:
Without TCP, data might get lost, duplicated, or arrive scrambled — like talking in a noisy room without confirming you were heard. (TechTarget)
Unreliable networks can cause:
TCP solves these by:
This means the application (like your web browser) can ask for data and trust what it gets.
Before two computers transfer data, they must agree to communicate — just like you and a friend confirm you’re both ready before starting a conversation.
This setup is called the 3-way handshake because three messages are exchanged:
The client (your computer) begins by sending a SYN packet to the server.
It tells the server:
“I want to start a connection, and here’s my initial sequence number.” (Network Walks)
Think of this as the client saying “Hello! Are you there?”
The server receives the SYN and replies with a SYN-ACK:
This tells the client:
“Yes, I’m here, and I’m ready. Here’s my sequence number too.” (System Design Codex)
It’s like the server saying “Hi, I heard you. Let’s talk!”
Finally, the client sends an ACK back to the server.
This confirms:
Once this last ACK is sent, the connection is established and both ends move to the ESTABLISHED state.
Now that the connection is established, TCP ensures reliable, ordered data transfer using:
Every byte of data is assigned a number. This helps both sides:
After receiving data, the receiver sends ACKs to confirm which bytes arrived correctly. If the sender does not get an expected ACK in time, it retransmits the missing data. (ScienceDirect)
This turns an unreliable network into a reliable stream of bytes.
TCP incorporates multiple mechanisms to provide reliable communication:
This is why TCP is used by systems that cannot tolerate missing or misordered data — like web pages, APIs, databases, and email.
Ending a TCP connection is just as important as starting it.
TCP uses special control flags:
FIN means:
“I have finished sending data and want to close my side of the connection.”
It does NOT immediately close everything.
It only signals that one side is done sending.
ACK means:
“I received your message.”
It is used throughout TCP communication — including during shutdown.
Sometimes a device sends FIN and ACK together.
This means:
This happens when a device finishes sending data and has nothing more to transmit.
Closing a TCP connection happens in four steps.
This allows both sides to finish sending remaining data safely.
Client sends FIN:
“I am done sending data.”
Server replies with ACK:
“I received your FIN.”
Now the connection becomes half-closed.
The server can still send remaining data.
When the server finishes sending its data, it sends its own FIN:
“Now I am also done.”
Client acknowledges the server’s FIN with ACK.
Now both sides agree:
Communication is finished.
The connection is fully closed.
Often:
This allows graceful shutdown without cutting off data.
TCP does not assume both sides finish at the same time.
One side may finish earlier.
The four-step process ensures:
This design makes TCP stable even in long-running connections.
TCP is much more than just “sending data”.
It is a complete communication system that:
Every website you load, every API you call, and every file you download depends on this invisible handshake process working perfectly.
Understanding TCP makes you a stronger backend engineer, system designer, and network-aware developer.