DEV Community

Rahul kumar parida
Rahul kumar parida

Posted on

TCP working (Communication Between Networks)

TCP (Transfer control protocol) is itself is a lot to understand in theory, Let’s start slowly by understanding where it came from .

TCP is a reliable control protocol residing or works in transport layer of the TCP/IP network model. its primary work is to transmit data over the network to a reciever’s end.

So how does it do that. Let’s walkthrough the process step by step :

1. Adding the layer : Transport layer adds a layer over the data which includes some required data such as IP header , Ordering , Control Flags , Checksum(Error Control mechanism)

a. IP header : Containing the source and the destination address along with some metadata.
b. Ordering : TCP send the data in order so it provide a serial number to each of the data packets such that receiver can order them as expected.
c. Control Flags : These are the flags containing the signaling what it the could be the next block of packet might contain. These are of few types:
i. SYN: Syncronizes with the receiver end initializes the data transfer.
ii. ACK: Acknowledgement which are sent until the connection is going on and required.
iii. FIN: Finish is the final signal first sent by the sender to receiver and then from receiver to sender to close the connection.
iv. RESET: Resets the connection for sending the data from the sender to reciever again in case the data is corruppted or failed to reach .
d. Checksum : This is sent to verify that the required data is reached or not and if there is any data loss during transmission.

2. Connection is established : The connection is established from the sender to reciever through a process of 3-way handshake. The sender sends signals SYN to initiate the connection , the reciever reads and replies with a SYN and ACK and then sender sends a ACK to fully establish the connection between them.

3wayhandshake

3. Data Packet Transfer : Once the connection is established the data packets are sent one by one from the sender to the reciever from a single consistent network. The sender sends data once the data is reached it is checked using checksum if the data length matches then the reciever send a ACK to the sender and sender sends another chunk of data if error is found in the data packet the reciever does not send the ACK and after a interval the sender understands that the data was not recieved properly and that is why no ACK so sender retransmits the same packet again .

Data communication

4. Closing connection: Once all the data is transffered and the data is recieved successfully the sender send the final block and FIN which is acknowledged by the reciever and then a ACK and a FIN is sent to the sender , the sender again sends the FIN to reciever and finally ends the connection this is a 4-way handshake. Data transffered successfully.

4wayhandshake

This is the complete process of how TCP works , it establishes a secure connection does the data transfer and closes the connection this is a large process but it happens so fast that you feel like nothing happend.

Advantages of TCP:

  1. TCP is reliable all the data is sent without any error or any loss
  2. Network Congestion Control: Which is the best part if the network is crowded and slow , then TCP packets sending time interval increases so that no data loss is done and if the the network has less traffic or less crowded then the time interval decreases and the packets are sent faster.
  3. Error handling statergy: TCP uses checksum which is used to calculate if the length data packet sent matches the data packet recieved and if the length matches upon calculating on the reciever’s side then the data is most likely intact

TCP is designed to solve reliability over an open connection of large network such as the Internet so that the data could be transmitted securely without any data loss and in correct order compromising a slice of time which is accepted because the time is almost negligible 99% of the time.

This is my understanding of how TCP works and what it is!! Thank you for reading till the end . Would love to get any feedback possible!!

Top comments (0)