TCP and UDP are protocols that are a part of the transport layer in the OSI model. Both of these protocols are used for sending packets over the internet. They are built over the Internet Protocol(IP) that is the reason why they are commonly known as TCP/IP which indicates TCP over IP and UDP over IP is referred to as UDP/IP.
Now before directly going towards TCP vs UDP. We should have a basic knowledge of what TCP and UDP are and how do these protocols work.
What is TCP?
TCP/IP stands for Transmission control protocol/Internet protocol. It is a connection-oriented protocol that is used by computers to communicate over the internet.
How does TCP work?
A TCP connection is established with the help of a three-way handshake, which essentially means if we have two computers communicating via messages and computer A sends SYN packet to computer B and receives back SYN/ACK from the computer B, Finally, A sends the ACK packet to B. They both establish a reliable reference to which they’re going to start the particular data transfer. It is also called the connection-oriented protocol.
What is UDP?
UDP(User Datagram Protocol) is an alternative transmission protocol to TCP which is most commonly used for establishing low latency connections between the applications on the internet.
How does UDP work?
It supports a two-way handshake, where a computer A sends SYN packet to computer B and receives back SYN/ACK from the computer B and the connection is established. It does not require the ACK packet from the sender to confirm the successful transfer of data and hence is called a connectionless protocol.
Difference between TCP and UDP(TCP vs UDP)
|It is a connection-oriented protocol.||It is a connectionless protocol.|
|Establishes a three-way handshake.||Establishes a two-way handshake.|
|Reliable as it guarantees delivery of data to the destination.||Not as reliable as the delivery of data is not guaranteed.|
|It does provide feedback.||Does not provide feedback|
|It offers retransmission of lost packets.||There is no retransmission of lost packets in UDP.|
|TCP provides extensive error checking mechanisms. It is because it provides flow control and acknowledgment of data.||UDP provides error checking by using checksums.|
|TCP does not support broadcasting.||UDP supports broadcasting and multicasting.|
|TCP has slower rate of data transmission.||UDP has faster rate of data transmission.|
|Applications that use TCP protocol are all messaging platforms, World Wide Web(HTTP,HTTPs),FileTransfer Protocol(FTP),Email(SMTP).||Applications that use UDP are video streaming platforms, VPN tunnelling, Live broadcasts, Domain Name System(DNS), Voice over Internet Protocol (VOIP).|
Advantages of TCP
- Retransmission-When a sender doesn’t get an acknowledgment after a certain period from the receiver. It will assume that the packet got lost on its way. So, the sender will send it again.
- Ordering-TCP transmissions are sent in an order and they are received in the same order. In the event of data segments arriving in the wrong order, TCP reorders and delivers the packet.
- Error Control
- Congestion Control– Delays the delivery of packets when the network is congested.
- Bigger packet size.
- Data doesn’t get sent out immediately.
- A real-Time conversation will not feel like real-time due to delays.
Advantages of UDP
- Faster Transmission– As the UDP packets are smaller in size than the TCP packets, hence they travel faster.
- Applications that need constant data flow, bulk data and which require fastness than reliability uses UDP over TCP.
- It is a connectionless protocol hence no connection to make or maintain, hence no delay.
- Due to the primitive form of error detection in UDP sometimes the data gets corrupted.
- There is no compensation for lost packets.
- There is no particular order of packets. Packets can arrive out of order.
- No congestion control.
UDP is lightweight but not that reliable so video streaming and live streaming based on UDP since it doesn’t require any ordering of packets and it could improve the speed of data transfer.
Although TCP is packets are larger than UDP and requires more time
but it is quite reliable and hence is used for mailing and messaging services due to its error checking mechanism.