Both UDP and TCP are transport layer protocols. The main difference between TCP and UDP is, TCP is a connection-oriented protocol, whereas UDP is connection-less. In other words, TCP needs to establish a connection prior to data transfer whereas UDP doesn’t.
What is Transport Layer?
TCP and UDP both are the protocols used in Transport layer that facilitates data exchange between source and destination host.
Transport layer enables multiple applications to use single dedicated network connections simultaneously and responsible for transmitting messages over the network .
It generates ports in order to allow applications running on the system to use them to connect themselves.
How does Transport Layer work?
When an application sitting at application layer sends a message to other host on the network, the message is handed over to transport layer where that particular message or data wrap inside a segment which consists additional information such as source and destination. After a segment is created, it is passed on to the network layer for further processing.
At the receiver end, the segment is accepted by the network layer and further delivered to the transport layer.
In the Transport layer, the actual message is unpacked and passed to respective application port specified in the segment.
Difference between TCP and UDP in Tabular form:
Basis | TCP | UDP |
---|---|---|
Definition | It establishes and maintain a dedicated connection before data transmission between hosts | it doesn't require to establish and maintain any dedicated connection prior to data transmission between hosts |
Full form | Transmission Control Protocol | User Datagram Protocol |
Connection type | Connection-oriented protocol | Connection-less protocol |
Header Size | 20 Bytes | 8 Bytes |
Congestion control | It delays the data transmission when the network is congested which minimises the packet loss | Don't support congestion control |
Overhead | Involves high overhead such as acknowledgement, data retransmission and more | Involves low overhead |
Delivery acknowledgement | When data packet is sent to destination host, it response back with an acknowledgement that is, it has received that data | No such feature is exist in this protocol |
Packet retansmission | When no acknowledgement is received within a specific time period, it assumes packets are lost and resend them again | No such feature is exist in this protocol |
Conceptually Known as | Steam-oriented | message-oriented |
Ordering | Segment are numbered as a result it is received at destination in same sequence in which they are sent | Message sequence is not maintained |
Speed | Slow | Fast |
Reliability | It is reliable | It is not reliable |
Connection Establishment | Connection must be established. It uses 3 way Handshake to achieve this | Data is sent without connection establishment |
Also refer to | Heavy-weight protocol | Light-weight protocol |
Packet drop rate | Very Low | High |
Error Control Mechanism | Checksum, Acknowledgement, Retransmission | Checksum . However, it is not mandatory |
Flow control | Sliding window is used for flow control | No such feature is exist in this protocol |
Used by | HTTP,SMTP and FTP are some examples | DNS and VoIP are some examples |
Suitable for | Applications that require high reliability, and transmission time can be compromised | Applications that require timely data transmission and reliability or packet drops can be compromised |
TCP (Transmission Control Protocol )
Transmission Control Protocol is more reliable than UDP. It is a connection-oriented protocol that means it establishes and maintains a dedicated connection before data transmission.
This process is called 3-way handshake.
-> Makes a request to a server for connection setup
-> Server responses back to the client and when the client receives the response
-> Client sends the packet to server that acknowledges that connection has been established.
For closing the connection, it follows a similar procedure.
TCP is steam-oriented which means that an application sends data in a continuous flow of data and it doesn’t have control on data splitting. for example, Phone calls.
Segment enclosing the data are numbered, therefore, TCP assures the sequence of messages or data must be delivered in the correct order to the destination host.
TCP supports several features. Some of these are :
Delivery acknowledgement:- When a data packet is sent to the destination host, it responds back with an acknowledgement that is, it has received that data.
Packet retransmission: When a sender doesn’t receive a delivery acknowledgement within a certain amount of time, it assumes that the packet is lost and send the packets again.
Congestion control: It delays the data transmission when the network is congested which minimises the packet loss.
Drawbacks of using TCP
- It uses a bigger header of 20 bytes
- It doesn’t send out immediately which delays the transmission
- It involves high overhead such as acknowledgement, data retransmission and more.
UDP( User Datagram Protocol )
UDP has a smaller packet size than the TCP, having header size 8 bytes.It is a connection-less protocol which means it doesn’t require to establish and maintain any dedicated connection prior to data transmission.
It provides more control over the way in which data should be sent.
However, data corruption is common on a network, UDP uses a primitive form of error detection which is backed with checksum but this technique is not reliable. Therefore, it is difficult to recover data even after error detection.
It sends data once only and therefore, any loss of data is not counted. It also doesn’t guarantee in which order packed would be delivered, meaning it is not necessary to receive data in the same order as it sent from the source.
There is also no congestion control in UDP, meaning no matter how busy the network is, it would send data continuously, that triggers packet drops.
UDP is lightweight but not reliable. It is message-oriented which means application send their data on distinct chunks, such as email.
Key Differences:
- TCP stands for Transmission Control Protocol, whereas; UDP stands for User Datagram Protocol.
- TCP is connection-oriented, whereas; UDP is a kind of type of protocol which is connection-less or datagram oriented.
- In TCP, there is a primary requirement for setting up the connection between the sender and the receiver and then only the transmission of data is proceeded, while, in UDP protocol, a broadcast mechanism is used for transmitting information, result in the requirement of establishing the connection between the sender and receiver is not needed.
- In TCP protocol when it comes to reliability, the TCP protocol gives cent percent guarantee of delivering the data to its respective destination, whereas; in UDP protocol as there is no connection maintained.
- In TCP protocol when it comes to error checking, the TCP protocol provides a full-fledged set of advanced error checking methods and mechanisms, whereas; in UDP protocol the error checking is very nominal and reduced to a minimum and basic error checking methods and mechanisms.
- TCP protocol transmits the data in the proper order, whereas; in UDP protocol the data is not sequenced.
- The TCP protocol is feature loaded and very secure which makes it very heavyweight, whereas, the UDP protocol has minimal features which make it very lightweight.
- In TCP protocol, there is a header size of about 20 bytes, whereas; in UDP protocol, there is a header size of about 8 bytes.