TCP Working: 3-Way Handshake & Reliable Communication
lets imagine a situation in which are trying to send a 1,000-piece Lego castle to our friend across the country, but instead of putting it in a box, we drop each individual brick into the mailbox one by one.
Without rules, what happens:
If brick #42 falls out of a mail bag, your friend has no way of knowing it’s missing until they try to build the castle and realize they're stuck.
Brick #500 might arrive on Tuesday, while brick #1 doesn't show up until Friday. Your friend is left with a pile of pieces and no idea where to start.
A red brick might get crushed or swapped with a blue one during transit.
In the digital world, sending data without rules (specifically without TCP) means our images would look like static, emails would have missing sentences, and software downloads would simply fail to run.
Here comes the role of TCP (Transmission Control Protocol) is like a registered letter that requires a signature. It is obsessed with accuracy.
Working : It performs a Three-Way Handshake. The browser says "Hello," the server says "Hello back," and the browser says "Okay, let's start."
Reliability: If a piece of data (a packet) gets lost on the way, TCP notices and says, "Wait! I missed a box. Send it again."
Order: It ensures that if you send packets 1, 2, and 3, they arrive as 1, 2, and 3.
Use case : Anything where losing data would be a disaster—like loading a webpage (HTTP), sending an email, or downloading a file. If you lose one packet of a file, the whole file is corrupted.
:) copied from { https://chaitaksh.hashnode.dev/tcp-vs-udp-when-to-use-what-and-how-tcp-relates-to-http?showSharer=true }
The Three Way Handshake
Before any data is exchanged, the Client (my browser) and the Server must agree to a contract. They do this through the 3-Way Handshake.
Step 1: The Request (SYN)
Browser wants to talk to Server. She taps him on the shoulder and says:
hello! server i want to sync with you. my starting point is 100.
- In Technical terms: This is the SYN (Synchronize) packet. Browser sends his "Sequence Number" so Server knows where his part of the conversation begins.
Step 2: The Response (SYN-ACK)
Server turns around and says:
hi ! browser i acknowledge your starting point of 100. I want to sync with you, my starting point is 5000.
- In Technical terms: This is the SYN-ACK. Server does two things: he acknowledges browser's number (usually by adding 1 to it) and sends his own synchronize number.
Step 3: The Final Confirmation (ACK)
Browser hears Server and gives a final thumbs up:
got it! i got your starting point is 5000. Let’s connect :))
- In Technical terms: This is the ACK (Acknowledge). Now that both sides have confirmed they can send and receive signals, the "virtual pipe" is open.
Imagine we are reading a story sent via text messages (probably from a girl), one sentence at a time. If you receive sentence #1 and #2, but then #4 arrives, we know immediately that we missed #3.
TCP handles this using a "Wait and Resend" strategy:
Every time the Server sends a packet, it starts a tiny invisible stopwatch.
Under normal conditions, the Client sends back an ACK (Acknowledgement) saying, "I got packet #3!"
If the Server's stopwatch runs out and it hasn't heard back from the Client about packet #3, it doesn't give up. It assumes the packet was lost in transit and automatically sends a duplicate of packet #3.
Hence, whenever we encounter a website lagging before popping, it might be the TCP which is quietly getting/ duplicating the lost packet for us without much telling us.
Connection Termination:
when we are about to hang up the call of a nearer-dearer, we usually end saying “GoodBye!“ instead of hanging up the call in between a sentence. The same goes for TCP, it does the same thing using FIN (Finish) flag. This Shutdown happen in two phases:
Phase 1: The Client is done
FIN: our browser tells the server, "I've sent all my requests. I'm ready to stop talking."
ACK: The server responds, "Got it. I'll stop expecting new messages from you, but give me a second to finish sending the data you already asked for."
Phase 2: The Server is done
FIN: Once the server finishes sending the last bit of the webpage, it sends its own message: "Okay, I’m done sending data too. GoodBye!"
ACK: my browser sends a final "Goodbye!" back.

this image too is generated by AI, i had also drawn the diagram ideas individually , but what AI does is something crazy , holding my concepts more better than before.