In the previous section, I introduced you to the OSI and TCP/IP models, in which the Transport layer is the layer that both models have.
Meanwhile, the transport layer is the layer responsible for logical communication between applications running on different servers, operating through two protocols, TCP and UDP.
The TCP protocol is more reliable, guaranteeing the quality of the transmitted packet, but it takes time to check the data.
As for the UDP protocol, the data transmission speed is faster, but it is not as reliable because there is no verification mechanism like the TCP protocol.
Okay, if you are also interested in this knowledge, let’s learn more about these 2 types of protocols at the Trasnport layer!
#first. What is TCP protocol?
TCP (short for the phrase ) BILLIONmission OLDontrol Protocol) is the transport protocol connection direction (Connection Oriented), that is, before connecting, a remote connection must be established. This process is called the 3-way handshake.
More specifically, the following:
Assuming PC A want to transfer data to PC REMOVE then, PC A will first have to establish a TCP connection to host B through a 3-way handshake:
Step 1: PC A sends PC B a packet with the SYN flag turned on, with the sequence number marked n
Step 2: PC B receives PC A’s SYN packet, it resends a packet with a SYN flag with SEQ sequence number of maccompanied by the ACK flag with SEQ sequence number n+1 To confirm.
Step 3: PC A receives a SYN from B and resends the packet with a SYN with SEQ sequence number . n+1 accompanied by the ACK flag with SEQ sequence number m+1
=> After 3 steps are completed, TCP connection is established between two machines A and B and can transmit data to each other.
Thus we can see, TCP has an ACK (Acknowledgment) mechanism used to confirm whether the data has been transmitted to the destination or not, and a packet numbering mechanism (Sequencing) for the purpose of assembling packets. exactly at the time of sending and receiving packets to avoid duplication.
If no response is received, it will resend the packet to ensure the process is not lost. Therefore, data will not be lost on the transmission line, but in return the data transmission speed will be slow.
#2. What is UDP protocol?
UDP (short for the phrase ) User EASYatagram Protocol) is the transport protocol direction not connected (Connectionless).
The UDP protocol does not have a 3-way handshake like the TCP protocol, but instead, it will transmit data immediately, bypassing the authentication mechanism as well as numbering the packets.
Packets are continuously sent to the receiver, the sender does not need to “wait” to see if the receiver has received it, but continues to send.
Therefore, if the receiver loses some packets, it will be lost (the sender will not resend), which is also why applications using UDP protocol will be very fast, because it has Skip the error checking step when transmitting the packet.
A simple example for the UDP protocol is Game Online.
Try to imagine when Thach is playing an online game like League of Legends such as.
The server will continuously send a series of UDP packets to Thach’s computer, in a very tense fight, unfortunately Thach lost his life, Thach could not control his champion to continue fighting ᵔᴥᵔ
Yes, and by the time the Internet connection was back, the fighting was over and Thach was on the scoreboard
Thus we can see, the sender is the server that continues to send the packet without knowing whether the receiver received it or not.
The same goes for when you are watching a live video (Live Stream) so if the connection is lost – your video will be paused and then it will go to the next latest broadcast.
Bypassing the error correction mechanism helps UDP increase connection speed and reduce real-time latency, something very important in Online Games and Live Video.
#3. Compare TCP and UDP protocols
|Connection direction||Direction not connected|
|Slow speed||High speed|
|There is an authentication mechanism in case of packet loss||No authentication mechanism for packet loss|
|Packet Marking||Do not mark packets|
|High reliability||Low confidence|
|Header 20 bytes||8 bytes header|
Okay, so you got it What is TCP protocol? and What is UDP? then right?!
Through the above analysis, we can see that TCP or UDP protocols have their own advantages and disadvantages.
Depending on the specific case, as well as the needs of use, we will choose accordingly. For applications that need high reliability and do not need to be too fast, we will use TCP, such as websites, emails, or sending data, etc.
As for applications that need to have fast speed, low latency, etc., we will use the UDP protocol. Such as Online Game, Livestream, Online Video, etc.
Hope the information in this article will be useful to you, don’t forget to share the article if you find it useful!\
CTV: Dinh Hoang Thach – Blogchiasekienthuc.com
Edit by Kien Nguyen
Note: Was this article helpful to you? Don’t forget to rate the article, like and share it with your friends and family!