TCP Working: 3-Way Handshake & Reliable Communication

Let’s understand one by one ….
What is TCP and why it is needed?
Problems TCP is designed to solve.
What is the TCP 3-Way Handshake?
Step-by-step working of SYN, SYN-ACK, and ACK.
How data transfer works in TCP?
How TCP ensures reliability, order, and correctness?
How a TCP connection is closed?
Before jumping directly into the TCP let’s understand how a computer communicate with other computers. For example we humans communicate with each other in a common language which can be Hindi , English , Bhojpuri, Maithili etc.
In computers, language can be UNICODE or ASCII. And let’s suppose two computers are there and they can understand different language. so, how to make them communicate with each other? There must be some conversion mechanism or rules to make it understandable to every devices/machines. So that’s called as PROTOCOLs in computer science, and TCP/IP is one of such protocols.
What is TCP and why it is needed?
TCP stands for Transmission Control Protocol is a foundational, connection oriented networking protocol that ensures the reliable,ordered and error-checked delivery data between applications through the Internet.
It is needed because it comes with guarantee of transmitting the data with a variety of functions like relaiblity,error checking, ordering , flow control, congestion control and re-transmission in case of error or courupt file. we will see the meaning of these terms in next section of problems TCP is designed to solve.
Problems TCP is designed to solve
Its helps to solve fundamental networking issue like data loss or packet loss, network congestion, out of order delivery and overwhelmed of reciver.
Reliabllity: Ensures that the data arrives at the recivers by checking the sequencing number and if data lost than re-transmit the data again.
Out of order/Ordering: By dividing the data into packets, it is transmitted to the receiver. At the receiver's end, the packets are rearranged in their original order to recreate the same data that the sender sent.
Error checking/Data corruption: TCP use checksum to verify the data is not altered or corrupted during transmission.
Network Congestion: TCP pick the best and least traffic route to transfer the data so that the traffic or we can say overloading is reduced which sometimes cause slow transmission of the data.
Control Flow: TCP use this to manage the flow of data to remove the overwhelmed situation of slow receiver.
What is TCP 3-Way Handshake?
As we know TCP is a connection oriented protocol, which mean before sending any data we need to first build the connection between server(receiver) and the client(sender).
Lets understand the concept of 3 Way handshake with the help of a diagram…

We can see here in picture what is actually happening step-by-step, It’s called building the connection.
SYN(Synchronise) : First client will send a request to server to start the connection.
SYN-ACK(Synchronise - Acknowledgment) : Server will reply the client with ACK single.
ACK(Acknowlegment) : Client will acknowlege that again and then send it to server, I am ready to send data.
How Data Transfer works in TCP?
Segmentation and Sequencing: First the data from client gets divided into small data packets and each packet is assigned a order sequence number which helps the receiver to rearrange them into original order.
Acknowlegment: Its ACK bit or flag which is sent by receiver to inform that the data packet is received if ACK missed or not revceived by the sender after certain time interval, it is marked as lost or corrupt. In that case sender retransmit the data.
Full-Duplex Communication: Once the connection is stablished between sender and the receiver it become full duplex which means now sending and receiving the data is done simountaneously.
Flow Control: TCP also keep eye on the flow or we can say speed of transmission to prevent the overwhelming of the server.
How TCP ensures reliability, order and correctness?
TCP manage all this by utilising the connection oriented approach, checksums, acknowlegment , sequence number, network congestion and flow control.
Reliability (Guarantee of delivery) , Flow Control (prevent Overwhlem of server) , Ordered delivery ( correct sequence).
How a TCP connection is closed?
A TCP connection is closed by 4-way handshake process.

As we can see here first client will send the information about the end of data to the server , server will acknowlege that and than it send all remaining data that is left for the previous request of the sender/client. and at last sender will acknowlege that and finally connection is closed until the client reopens it by sending another request ie, searching something on web again.
FIN(Client to Server) : Sender will send this to server. it mean i am done i have no more data left to send.
ACK(Server to Client) : Receiver acknowlege that and send this signal before stoping the further transmission from receiver end to sender end.
FIN((Server to Client again): Server transfered all remaining data after ACK signal and then send final FIN to asure the client that no more data left to transmit(I am done).
ACK(Client to Server): Finally client will respond to the server FIN by ACK that yup i got you. and finally connection gets closed.
Conclusion
TCP is smart but slow, because it know how to manage everything but due to this it takes longer time to transfer the data form sender to receiver because most of the time gone for verifying and analysing the data.




