I decided to write about something a little bit fun something that’s not data structures and algorithms, guys pls if you find value in this and love this sort of content do let me know.
Today we are going to talk about TCP this would be an overview from a software engineering perspective.
Let’s go…
What’s is TCP?
TCP stands for (transmission control protocol).
TCP and UDP are both layer 4(Transport Layer) protocols of the OSI Model.
TCP allows for transmission of information in both directions. This means that computer systems that communicate over TCP can send and receive data at the same time making use of the IP address and port
TCP is used in a lot of applications example: databases, secure chatting apps, etc.
Let’s see some examples of TCP in real-life…
HTTP (world wide web)
SSH (Secure Shell)
E-mail (SMTP TCP)
File Transfer Protocol (FTP)
Why is TCP used
TCP was created so that it would be a reliable, and straightforward way to pass data around without ending up with a scrambled or lost data, this way software engineers do not need to write code to handle this situation. Thereby allowing them to focus on application logic.
Let’s look at some characteristics Advantages of TCP.
Acknowledgment/Confirmation
Let’s use an example to explain this. Due to the unreliability of the internet, a lot of things can happen to data on transit from client to server.
We need some sort of confirmation that the data we have sent has gotten to its destination.
TCP is able to do this by attaching additional information to the data that’s being sent.
If our client doesn’t receive this confirmation it doesn’t accept the data.
Retransmission
In a situation where our client did not receive a confirmation from the server the TCP (transmission control protocol) does the job of informing the server that the data wasn’t received so that the data is resent.
This is called RETRANSMISSION where it keeps sending the data until it knows that we have received it.
This is often a tradeoff. Because of the guaranteed delivery capability of TCP, it tends to be slow.
Connection
For a client to communicate with the server, a unique connection is needed. TCP uses the IP to establish a stateful connection.
This is why it is able to carry out retransmission and acknowledgment/confirmation. This is how the server knows that it has a client that it needs to send data to.
Congestion control mechanism
The TCP stops once there is a lot of traffic and waits for when there is less traffic then it resumes sending the data.
This is because on the internet there is a lot of packets/information/data going around, so our packets get delayed when the server is overwhelmed.
This happens when a lot of people are sending packets all over the internet.
Packets Ordering
Because the internet does not guarantee that the packets you send would be received in an orderly manner.
TCP has the capability of ordering our packets, by adding identifiers to our packets or data, so this is what it does to enable it to order our packets.
An example of this would be sending a long-detailed email to a friend, what TCP does, in this case, is to break this data into smaller pieces and then orders them.
This helps them to arrive on the server in an orderly manner and prevents unnecessary data loss.
Let’s see some characteristics Disadvantages of TCP.
Large Packet size
TCP usually ends up with larger packet sizes, this is due to all the extra identifiers and informations it adds to the data that it sends.
These identifiers help it achieve retransmission, packet ordering, congestion control, etc.
Larger Bandwidth
With larger packet size comes more bandwidth.
Slow
The delay involved with TCP is due to things like packet ordering, congestion control, retransmission, acknowledgment/confirmation, etc. Basically the advantages of the TCP are the actually things that makes it slow.
Stateful
TCP is stateful, this is because the server and client carries info information about the connection.
So, if in any way the server or client is closed our connection is lost.
Server memory
The server stacks up the TCP connection and allocates memory for each of these connections.
The server has to keep listening so that it knows when it receives data from any part of the connection.
This is possible because of the statefulness and connection-based characteristics of the TCP.
So, in a situation when someone tries to establish a connection to the server using the TCP.
Due to the fact that the server does some kind of waiting, because of the connection, acknowledgment/confirmation, retransmission, guaranteed delivery, packet ordering and congestion control, a bad-client uses these features against the server to create a kind of DENIAL OF SERVICE attack (DOS).
So, this bad client keeps sending a connections request, without letting the server go through the normal process of acknowledgment, retransmission, etc.
This keeps the server waiting until there is a timeout, and the server crashes, this is a very simple explanation of how DOS is perpetuated.
The layer 4 or otherwise called the transport layer also has another transport protocol called UDP (User Datagram protocol).
In another article we would be touching in this.
Until then stayed tuned!!!
With this, we have come to the end of this article.
Guys as always thanks for being here with me. I really appreciate it.
And if you found any sort of value in this please leave a comment share it on Twitter it really does help get the word out so that other devs can find value in it.
Once again thank you for sparing the time to read this article.
If you’d love me to implement a TCP server using NodeJS.
Do let me know and I will do just that.
Much Love.❤❤❤
Top comments (2)
very nice article summarizing key features of TCP protocol without reading a big academic book.
Thanks. Am happy you found value in it.🤓🤓