TCP Working: 3-Way Handshake & Reliable Communication

Search for a command to run...

No comments yet. Be the first to comment.
CSS selectors are a way to choose elements. It helps to target a specific HTML element or a group of elements to style them in CSS. Think of it like addressing people; one is you’ll say, “All people just listen to me,” another is “People with green s...

First we will see what Emmet is. Emmet is a free and open-source toolkit for text editors to boost the speed and efficiency of coding languages like HTML and CSS. Think of it like a shortcut language for HTML. It provides us with various short abbrev...

HTML (Hypertext Markup Language) is a standard language used for creating the structure of web pages. It’s like the skeleton of a web page, which defines which thing should be where. HTML is very important in creating web pages because without this a...

We use browsers daily to browse websites, but have you ever thought about “What happens when I type a URL and press enter?” In this article we’ll understand how a browser works and what process happens behind the scenes from when we hit enter until t...

Think if millions of computers start communicating with each other without any rules, there will be chaos. That is why we need protocols like TCP and UDP to make communication effective and meaningful. In this article we will understand TCP and UDP t...

TCP (Transmission Control Protocol) is a networking protocol that allows devices to communicate reliably over a network. It ensures reliable, ordered, and error-free transfer of data between applications. TCP works on the transport layer of the OSI model.
The question is “Why will we not communicate without TCP?” There are a lot of problems without TCP.
There is no agreement on how communication should start.
There is no guarantee that data will arrive.
There is no ordering of data received.
No mechanism to detect missing data.
No confirmation if data is received or not.
There is no agreement on closing the connection.
To solve these problems, TCP was built; it solves all these problems, which we will understand in detail in this article.
Before sending the actual data, TCP establishes a connection and ensures that the receiver is available by a method called the 3-way handshake. Think of you need to start a conversation with a friend; you tell your friend, “Hey, are you there?” Your friend replies, “Yes, I’m here. Are you there?” You say, “Yes, I’m also here. Let’s talk.”
TCP does similarly before sending the data. These steps are SYN, SYN-ACK, and ACK. Let’s understand the step-by-step working of SYN, SYN-ACK, and ACK.

Step 1: SYN (Synchronise)
The sender sends a SYN packet to the receiver.
It means, “I want to connect."
Step 2: SYN-ACK (Synchronise-Acknowledge)
The receiver replies with SYN-ACK.
“I received your request.” (ACK).
“I’m ready too” (SYN).
Step 3: ACK
The sender sends an ACK.
It means “I received your response.”
With these steps the sender and receiver establish a successful connection, and both are ready to send and receive data.
TCP breaks the data into smaller segments; each segment contains some data and headers.
Headers contain information like sequence number, port, and flag.
TCP does not care about routing and addressing; it’s handled by IP.
After segments are created, these are handled to IP.
The IP address sends the segments through the network to the receiver, possibly through different paths.
Segments may arrive out of order because they can take different paths through the network.
Segments are reassembled through their sequence numbers.
The receiver sends ACK to the sender on each segment or group of segments it receives.
The sender waits for ACK; if it is not received for any segment, it retransmits that particular segment.
If the sender doesn’t receive ACK in a specific time, it assumes the segment is lost and retransmits it.
It ensures that every segment is received by the receiver, which makes TCP reliable.
Closing a TCP connection is similar to opening a connection, but this time it’s a four-way handshake:
FIN (Finish): The sender who wants to close the connection sends the FIN to the receiver.
ACK (Acknowledge): The receiver acknowledges the FIN with ACK.
FIN (Finish): The receiver then sends his own FIN when it’s ready to close the connection.
ACK (Acknowledge): The sender responds with an ACK, completing the connection termination.
TCP is a networking protocol that allows the transmission of the data reliably, orderly, and error-free over a network. TCP solves a bunch of problems like communication starting agreement, data arrival confirmation, data ordering, retransmission of missing or lost data, acknowledgement on getting data, agreement on closing the connection to ensure data is fully transmitted.
TCP starts a connection with 3-way handshaking SYN → SYN-ACK → ACK. And similarly closes the connection by 4-way handshaking FIN → ACK → FIN → ACK.
I’m a fellow learner, just like you all. If there is anything missing or incorrect in this article, do let me know. I’m always open to learning and mistakes.