TCP Working: 3-Way Handshake & Reliable Communication
What is TCP and Why is it needed?
Imagine!
What if data arrives “out of order”?
What if some data never arrives?
What if sender and receiver are not ready at the same time?
“Sending data on the internet without rules can definitely lead to loss, confusion and inconsistency.“
Once we are aware about the problems, we can start finding the solution. To solve such issues, TCP is introduced as a solution. Here we start the main discussion,
TCP:-
TCP(Transmission Control Protocol) is a transport-layer protocol. It provides reliable, ordered and error-checked delivery. TCP is used when data
correctness matter.
The major task of the TCP is to make unreliable networks behave reliably.
Problems TCP is designed to solve:-
TCP can easily handle packet loss. It solves the problem of out-of-order delivery. It can detect the duplicate packets of data. It can prevent Network congestion as well and it also resolves the problem of synchronisation b/w Sender and Receiver.
What is 3-Way Handshake?
3-Way Handshake is just the confirmation that both sides are agree to communicate before sending the data.
A connection is established to ensure that both client and server are ready and reachable.
In simple words, it starts as
“Am i audible?”
“Yes! Lets start.”
Working of SYN, SYN-ACK, and ACK:-
Step-1:
Client sends a SYN message means “I want to start a connection”. It includes an initial sequence number.
Step-2:
Server responds with SYN-ACK means “I am ready, and i acknowledge you request.“
Step-3:
Client sends ACK means ”I acknowledge your response-let’s communicate.”
After the third step, the TCP is connection is established.
How does data transfer work in TCP:-
DATA transfer in TCP is a sophisticated process designed to ensure that data sent over the internet is reliable, ordered, and error-free. TCP treats data as a continuous stream of bytes rather than independent packets.
1.DATA is split into segments.
2.Each segments has a sequence number.
3.Receiver sends acknowledgements (ACKs).
Sequence numbers help TCP keep data in the correct oder.
How does TCP ensures Reliability, Order, and Correctness?
Reliability:-
If data is lost, it can easily get detected and Missing segments are retransmitted.
Order:-
Sequence numbers are there so data gets reassembled and that’s how application receives data in correct order.
Correctness:-
Errors are detected and Corrupted data is discarded and resent.
How does a TCP connection gets closed?
Both sides must agree to close the connection and uses FIN and ACK
Step 1 → FIN "I have no more data to send."
Step 2 → ACK "I received your request to close."
Step 3 → FIN "I am also finished sending data."
Step 4 → ACK "I received your request; we are done."
This is similar like ending the phone call politely, not hanging up abruptly.