Skip to main content

Command Palette

Search for a command to run...

TCP Working

3-way Handshake & Reliable Communication .

Published
•5 min read•View as Markdown
TCP Working

What Happen if data is sent without rules .

  1. If we send data without any rules or protocols, many problems can happen.

  2. First, there is no guarantee that the data will reach the correct user. Data can be lost during transmission, and if data is lost, there is no way to recover it.

  3. For example, when we send large data, it is divided into small packets. These packets travel separately over the network. If even one packet is lost, the receiver will not get the complete data

  4. Another problem is that packets may arrive in the wrong order, not in the correct sequence.

That’s why we need a some rules and protocol of these issues, to transfer data safely and correctly. Their are two standard Protocol are there TCP and UDP .

What is TCP and why it is needed .

  1. Transmission Control Protocol is a protocol that allows devices to communicate reliably over a network. It is most reliable because they provide a guaranty data should be reached correct destination and in a correct order .

  2. If the network is slow and shut down by chance no data loss and does not change your data destination path, because they know IP Address where to sent or receive data packets . That’s why this is also called as TCP/IP .

What is the 3-way Handshake .

  • We already know that TCP provides a reliable connection, which means the data reaches the receiver correctly. Now let us understand what a 3-way handshake is.
  1. A 3-way handshake is a process used by TCP to establish a connection before data transfer starts.
    When a user wants to send data to a server using TCP, a connection must be created first so that both the client and the server know they are connected and ready.

Step by Step working of SYN, SYN-ACK and ACK .

  1. It is called a 3-way handshake because it happens in three steps:

    Client → Server: The client sends a request to the server saying, “I want to connect.”

    Server → Client: The server replies back saying, “I received your request and I am ready.”

    Client → Server: The client sends a final response saying, “I am ready too. Start data transfer.” Means it confirm the connection is established .

  2. After these three steps are completed, the connection is established, and now data transfer can begin safely using TCP.

How Data Transfer Work in TCP .

Data is transfer is reliable and reach in correct order.

  • Once your connection is build 3-way handshake is done . The Data Transfer is start .

  • Assume you are sending a 5MB data to server , not directly that your these 5MB file transfer alone over they network they create a latency and time consuming process .

  • They break first your file into small small data packets { like each file 1 MB } so you have a total 5 files .

  • Here TCP what they do they assign to each packets sequence number and IP Address , because when the data receive by other computer they resemble it and use accordingly .

  • That’s why TCP is used by chance if you one data packet file will be lost when they travel , then TCP start retransmission process find that data packet with help of it assign IP Address and sequence number .

  • Know you understand why a TCP is more reliable.

How TCP ensures Reliability, Orders and Correctness .

We have already seen how data is transferred and why TCP is reliable. TCP sends data in order and delivers it to the correct destination. Now let us understand how all these features work together, which makes TCP so powerful.

Let’s see step by step:

1. Retransmission

Retransmission means TCP makes sure that data reaches the receiver in every situation.
That is why TCP is called reliable.

For example, suppose you send a large file.
TCP breaks this file into small data packets and gives each packet a sequence number, like:

1, 2, 3, 4, 5

These packets travel to the receiver in this order.
Now imagine that packet number 3 is lost during transfer.

In this case, TCP will resend (retransmit) packet 3 again.
The receiver will not process the next packets until packet 3 is received.

So, TCP waits and fixes the problem instead of moving forward.
This is why TCP is reliable.

2. Order

Order means data is received in the same order in which it was sent.

If data packets are sent like this:

1, 2, 3, 4, 5

Then the receiver will also get them in the same order,
not like this:

3, 1, 2, 4, 5

TCP uses sequence numbers to make sure data stays in the correct order.

3. Correctness (Correct Destination)

TCP ensures that data goes to the correct destination only.

If you send data to Server A, it will not go to Server B.
This happens because TCP first creates a connection using the 3-way handshake.

How a TCP connection is closed .

  1. FIN means Finish, a sender (Client ) send to a data packet for close the connection .

  2. ACK means Acknowledgment , server sent reply okay know want to close a connection.

  3. FIN know server sent a Finish packet to sender ( client ) for close the connection.

  4. ACK then the last step is sender ( client ) a acknowledgment to server connection is terminated.

  • So this is how a TCP Connection Closed .
💡
so this is my thought on TCP Working how it is work and how data is transfer . I Hope you will understand it .