Content List
- 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
What is TCP and why it is needed
Think you have a 100 pieces puzzle, you want to share this to your friend. so you decide to give it to him. You pick each piece of puzzle and pack it into separate envelop and you give these envelops to your post office to deliver it to your friend, But there post office doesn't give guarantee of envelops delivered safely and in order.
Problems facing for deliver puzzle pieces envelops:
Missing Envelops: in the trip some envelops got out from the delivery truck.
In Order Delivery: post delivery service deliver the envelops in random order 99 pieces arrive before the 1 piece.
Delivered Damaged Pieces: in journey some envelops getting get or torn make puzzle incomplete.
To solve these problem you need a manager who handle delivery process to ensure the delivered all envelops safely, reliably, and in order. The TCP is also handle the same problems but in the conversation of computers networks.
In Networking TCP (Transmission Control Protocols) is the standard used to established secure connection between two peers client and server so reliable conversation can happen. There conversation here is bi-directional.
Problems TCP is designed to solve
In early computer networking lots of users face same problems we saw in the 100 pieces of puzzle. during the conversation lots of data packets had missed, delivered in wrong order and some times data packets broken during the conversation. so engineers sit and discussing about these problems and decided some set of rules which always followed during conversation we calling it TCP.
Timeout & Retransmission, used to handle data segments loss during the conversation.
Sequences Numbering, used to give a serial number to each data segment for in-order delivery.
Checksum Algorithm, used to handling data segments error to reduce data corruption during transmission.
What is the TCP 3-Way Handshake
Imaging you have a secret code which you want to share with your friend. You doing a step by step process: you calling your friend when your friend pick your phone. You asking like "hello, are you listening me" which ensure your call is connected to right person you want to. Your friend saying "Yes, I'm listening you" this ensure both side can listen and speak to each other for conversation. You than saying "Ok, lets start" after that you start saying secrete code to your friend.
This analogy explain clearly how reliable conversation connection is establish in real world just like it. In digital word TCP also use this type of technique called 3-Way handshake which ensure established connection is secure, reliable, bi-directional mean speak or listen each other at same time.
Your calling your friend and ensuring he's the right person, your will ask "Hello Babli, Are you there.
When your friend pickup the call and listen you. She replying "Yes Bob, I'm there".
When you here her and confirm she's right person. You saying "Lets, Talk", and start your conversation.
Step-by-step working of SYN, SYN-ACK, and ACK
In the world of computers for making 3-Way handshaking TCP use SYN and ACK flag in data segments header. The handshaking perform in 3 steps:
Information: Flag are the single-bit control fields within segments header which contain flag with number like
syn-1 ack-1. Header used to manage connection, indicate packet type, and control data flow.
SYN (Synch) : client like browser sending SYN request to intended server. It mean you want to ask to server are your available for me to make connection.
SYN-ACK (Synch and Acknowledgement) : When server received your SYN request and it available for connection with you than, It send back a SYN-ACK request. Which means it ready for estabilished connection with you and asking you, are ready for connection.
ACK (Acknowledgement) : When you received SYN-ACK request. This mean your can start establishing connection and he also make it. When you send ACK request to server than TCP connection is established for conversation, after that you can start conversation with each other.
How data transfer works in TCP
In the 100 pieces of puzzle analogy we have seen the random order problem, in that pieces envelops are delivered in any random order like 99th envelops delivered before the 1st piece envelop. lets see the what is the solution for that.
What happen if we using numbers printed on each envelop in delivery order and a temporary place aside the delivery address. instead delivery on directly to destination, envelops are deliver first at temporary or waiting place where those all envelops wait until all are delivered here. When they delivered in waiting area than we arranged them in order by using numbers printed on envelops and than efficiently deliver it to destination address.
This technique solve the in-order delivery problem. That how the TCP solve in-order data packets delivery. In TCP Sequence Number and Buffer. Sequence Number attached into data packets header which used to order them at destination side. The Buffer is like a waiting area where all data packets wait until all packets arrive, after that they arranged in right order to make full data sended from the source address.
Information: Destination Address and Source Address are attached to data packets at the Internet layer By the IP.
During the Handshaking each pear share own Sequence Number to each other:
- Client : when client sending ACK request the sequence number is attached to it. its like "hey server, i'm using 3000 sequence number".
- Server : when server sending ACK request he also attach its own sequence number. its like "ok, and im using 5000 sequence number".
How TCP ensures reliability, order, and correctness
Reliability : to reduce data packets missing during transmission. TCP use Timeout and Retransmission. Think its like when telling mobile number to some one on phone call your say 2 digit at a time and wait 2-5 sec (Timeout time) if your not recieved "Ok, next" (Acknowledgement) from the other side within waiting time, than you repeat these 2 digit (Retransmission). This is the technique TCP use for reliability.
Order : we already discussed about how TCP maintain in-order transmission, it use Sequence Numbers and Buffer Area.
Correctness : to ensure that arrived data packets are not corrupted or damaged, TCP used specialized algorithms like Checksum. Its perform some type of mathematical calculation based on arrived packets to generate a sequence of digits, sender and receiver compare both values the have if its matched then packets are correct if not matched then there are error in packet.
How a TCP connection is closed
TCP used flags like FIN, ACK-FIN, ACK, and RST to closing the current connection. Just like 3-way handshaking its also a 3-way process for closing the active connection.
FIN : it used for telling other server i'm done i don't have any data for transmission in this session. After that client enter into half close mode means the client cannot transmit any thing over this connection its like "only can listen, can't speak". if client try to transmit data during half close mode. The server close the session forcefully with RST flag. Which means make new fresh session for that transmission.
ACK-FIN : When server receive FIN request, than it send ACK-FIN request which means, i sent all data i have and not sending anymore data on this session and i'm ready for closing the connection.
ACK : After receiving the ACK-FIN request client sent ACK which means i'm closing the connection you can also closed it. At that time both side connection are closed.







Top comments (0)