TCP Working: 3-Way Handshake & Reliable Communication
TCP Internals

I am a problem solver and a full-stack developer. I love to write and share my knowledge. My wish is to learn and help others learn at the same time. Hoping to make a difference in the tech world.
What is TCP and why is it needed
TCP stands for Transmission Control Protocol
TCP is needed where reliable data transfer is a must.
Problems TCP solves
Data loss
Data Integrity
Congestion Control
Retransmission upon failure
No bandwidth constraints
etc.
TCP 3-way handshake
TCP always ensures that the connection between client and server has been established properly and verifies it with the 3-way handshake mechanism.
SYN - Checks if the client has reached out to the server or not
SYN-ACK - Checks if the server has confirmed that the client has reached out properly oor not
ACK - The connection has been established and is verified
Treat it like a real communication between two people over a phone:
Person A - “Am I audible?” - SYN
Person B - “Yes you are audible” - SYN-ACK
Person A - “Ok then I’ll start talking” - ACK
The sequence:
SYN → SYN-ACK → ACK

How data transfer works in TCP
First establish the connection (3-way handshake)
Then the data packets are sent one by one
Receiver confirms if each packet is sent or not
Only then the next packet arrives otherwise retransmission
It closes the connection each time
Example:
If three images were to be sent using TCP, it would establish the connection, send one image then close the connection and this will happen each time for all three images
How TCP ensures reliability, order, and correctness
In TCP, sequence numbers and acknowledgements are used to keep communication organized, reliable, and accurate, without getting into technical complexity.
Sequence numbers
they are labels of each packet
preserves ordering
helps identify missing or duplicate
helps reconstructing data after all packets are received
Acknowlegdgements
ACKs are:
confirmation of successful transmissions
tells how many packets received
Sequence + ACKs
makes data reliable
preservers ordering
keep track of packets
allows reconstruction

How TCP closes the connection
It’s just like how someone end the call:
Person A - “Let’s end the call”
Person B - “Ok, i heard you”
Person B - “Let’s end the call
and connection is closed, and also http is stateless, so it forgets history. That’s why TCP over http cannot be used for large downloads, for that we use FTP.



