This Tutorial Explains What is TCP, What is UDP and What is the difference between TCP vs UDP. You will also learn about their Functions & Applications:
In our previous tutorials, we have discussed the TCP protocol suite model and its features in detail. We have also learned about the UDP protocol.
In this tutorial, we will compare the various features, modes of operation, applications, speed, reliability, transmission characteristics, and security features of these two widely used protocols.
What You Will Learn:
What Is The TCP?
The TCP/IP protocol is a set of protocols of four layers. Overall, these four layers take the responsibility of the communication process and end to end delivery of data, voice, packets over the internet on inter and intra network.
The Transmission Control Protocol (TCP) works on the third layer of this protocol model which is the transport layer.
TCP is a connection-oriented protocol suite that ensures the delivery of data packet to the next node or destination node by employing a sequence number in each datagram and acknowledgment sessions with each of the communication sessions.
This system also ensures secure transmission on each layer for the data packets and thereby provisions the retransmission of data packets unless it reaches a timeout situation or it receives the proper acknowledgment message from the receiver.
These are the basic characteristics of the TCP protocol.
What Is UDP?
User Datagram Protocol (UDP) works on the transport layer which is the third layer of the TCP/IP protocol suite. In contrast to the TCP protocol, it is a connectionless protocol as it does not establish a connection before sending the data over the network for communication.
Thus it is best suited for the applications where there is no need for acknowledgments of the data packets required in the communication process such as watching videos online and playing games online.
TCP And UDP Communication Process
As shown in the above figure, the transmission control protocol is connection-oriented as it first set-ups the connection between two hosts and then starts the communication process. It is used for a secure mode of communication processes as it offers secure communication by using a 3-way handshake process.
It ensures the sequential and correct delivery of data from the sender to the receiver. If any error has occurred in sending the data, then the receiver will intimate the source that the data sent was incorrect, and then the source will re-transmit the data until the acknowledgment of proper delivery of data is received by him.
As shown in the above figure, the user datagram protocol is a connection-less protocol as no proper connection is established between host A and host B to start the communication. The hosts are just two end devices of any processes which are initiating communication.
The host A will keep transmitting the data and the host B will receive it without being the concern of the sequential and error-free delivery of data.
Thus this is an un-reliable protocol and is used where secure data transmission is not important but faster communication is required like in streaming video and playing games online.
Comparison Chart TCP Vs UDP
|Basic functionality||Transmission control protocol always firstly set up a connection between source and destination host before the start of any communication process of data packets.||User datagram protocol forwards data straight to the destination host without establishing any link between the source and destination end.|
|Type of connection||It is a Connection-oriented protocol which signifies that a connection must establish before the start of transmission of data and the communication devices should end up or terminates the connection once the communication is over between sender and receiver end.||It is a Connection-less protocol which signifies that there is no compulsion for establishing, maintaining and terminating a connection between source and destination end. It is best suitable for broadcast and multicast purpose.|
|Speed||The speed is slower than the UDP.||Fast then TCP. It is a real-time transport protocol.|
|Reliability||It is extremely reliable as through the acknowledgement process it ensures the proper delivery of data packet to the destination node.||The delivery of data packets is not ensured thus it is an unreliable protocol.|
|Header size||20 bytes||8 bytes|
|Acknowledgement||TCP protocol follows the handshake process between sender and receiver to acknowledge the receipt of data packets in both the directions. Thus this offers the facility of retransmission of lost data packets.||It never acknowledges the data receipt and hence there is no chance of re-transmission of data.|
|Protocols Used||The various kind of protocols used by TCP for data transmission is HTTP(hypertext transfer protocol), HTTPs(hypertext transfer protocol secure), FTP(File transfer protocol) and SMTP(Simple mail transfer protocol) etc.||The various kind of protocols used by UDP for data transmission is BOOTP(Bootstrap protocol), DHCP(dynamic host configuration protocol), DNS(Domain name server) and TFTP(Trivial file transfer protocol) etc.|
|Flow control||Flow control is done by using sliding window and congestion avoidance algorithms etc.||None process is followed|
|Data interface to the application||Data is transmitted in message-based distinct data packets||Data is transmitted in stream-based data packets and there is no specific structure is followed.|
|Error Checking||Error detection and correction is done by using a checksum and the data packets are retransmitted after correction from the sender to the destination end.||The lost data packets are discarded and error checking process is not practised.|
|Applications||Since this protocol offers a secure and reliable communication process, therefore, it is used in the services where data confidentiality is a prime concern like military services, web browsing and e-mail etc.||It is used where fast communication is peed is required and data reliability is not a concern like VoIP, game streaming, video and music streaming etc.|
UDP Vs TCP Header Format
- Source port: It contains the source port address of the data segment and it is of 16 bits size.
- Destination port: It contains the destination port address and is also of 16 bits size.
- Sequence number: This is of 32 bits in size. It represents the sequence number of the data segment of the first octet. If the SYN is available, then the value of the sequence number is ISN+1 whereas ISN stands for an initial sequence number.
- Acknowledgment number: The size of this field is also 32 bits. This field carries the sequence number of the very next data segment that the source end is expecting from the receiver to arrive as an acknowledgment of the receipt of the data packet. When a proper connection is established between the source and the destination end, this bit is always transmitted.
- Data offset: This field is of 4-bit length. This denotes the point from which the data initiates.
- Reserved: Some bits are reserved for future purpose and value in this field is zero. It is 6 bits long.
- Flags: This is also of 6 bits. Different flags are used for various purposes. As per the suitability, the flag is set to zero or one.
- Window size: The size of this field is 16 bits. This field contains the count of the data octet that begins with the one which displays in the acknowledgment number field and the sender is waiting to receive.
- Checksum: This is also of 16 bits size. The checksum is computed for all the data octet of the whole data segments. It is evaluated as one’s complement and again one’s complement of the output and then both the output is added to the present 16-bit header and text data of the octet. The outcome is also transmitted to the next upper layer for corrections.
- Urgent pointer: This field is of 16 bits size. If the URG flag is set, only then this field is computed. It denotes the sequence number of the data octet after the urgent data.
- Options: This is a variable field. This can be set at the start of any of the octet edge.
The UDP header has only 4 fields when compared to the TCP header and it is also very easy to understand when compared to the TCP header.
- Source port: This is 16 bits of length. It contains the value of the source port employed by the source end for transferring the data packet. The range lies between 0 to 65535.
- Destination port: The size of this field is 16 bits. It contains the port number which the destination host is expecting for receiving data.
- Length: This field size is 16 bits. It consists of the length size of the user datagram, header, and data.
- Checksum: This is also of 16 bit in size, but this is an optional field. It is used for the computation of the errors in the datagram. If it is set to zero, then checksum is not computed and if set to one then it will be computed.
Functions Performed By TCP
(i) Addressing and Multiplexing:
The TCP ports are used for addressing the various processes of the network for upper-layer applications. This also multiplexes the data collected by various procedures and then broadcasts the data packet in association with the network access layer.
(ii) To Establish, Sustain and Terminate Connections:
In this protocol, several sets of processes and rules are followed to set up a connection between the source and destination end. There are handshake protocols & methods and are used to maintain and acknowledge the ongoing communication process.
In the end, some rules are also followed to terminate the connection once the communication is over between the source and destination end.
(iii) Packaging of Data:
Before forwarding the data packets to a higher layer for communication, the TCP firstly provisions the procedure for packaging the data into message format for transmission and then delivers to the destination end.
At the destination end, the receiver decodes and unpacks the data and again forwards it to the upper layer applications.
(iv) Provisions Reliable mode of Communication and high QoS:
It offers a reliable mode for communication between a sender and receiving end and also ensures a high quality of service.
The mechanisms which are used by TCP for data transfer follow the set of rules which ensure the reliable delivery of data and also offer retransmission of missed or out of sequence data. The different handshake protocols are used to ensure reliable communication.
Functions Performed By UDP
(i) Higher-layer transfer of data: The UDP protocol receives the data to be transferred from the higher layer and then converts it to UDP messages and then transfers to the UDP software for communication.
(ii) UDP message encapsulation: The UDP message is encapsulated into the data field. The UDP header consists of the source port and destination port domains and figures out the checksum value as well.
(iii) Message transferred to the Next layer: After the computation of the above fields, the UDP message is forwarded to IP for communication. At the destination end, the process gets reverted.
Applications Of TCP
- The TCP is used in FTP (File transfer protocol) for sharing and sending big data files securely within the organization between the hosts that are situated far away.
- The E-mail process which uses the Simple mail transfer protocol (SMTP) also uses TCP for sending e-mail and data files among the various hosts into the organization and outside the organization.
- POP also makes use of TCP for recovering or downloading e-mail messages.
- The TELNET protocol also uses TCP for login and accessing the host situated at far-end or remote end securely.
- The Border gateway protocol (BGP) also works on TCP to offer a reliable mode of communication over the WAN networks.
- The military services use TCP for exchanging highly confidential data and information within their internet works.
Applications of UDP
- Streaming videos, streaming audio, etc where only fast data speed is important and lost data recovery are not taken care of.
- Playing video and graphic games online.
- UDP is also used in the tunneling processes and VPN networks where the lost data can be recovered later.
- UDP is also used in broadcasting purposes for the LAN network.
- Watching real-time TV on mobile phones is the latest popular use of UDP which is also known as IPTV.
We have explored the difference between the TCP vs UDP protocol with the help of figures and tabular comparison chart. On one hand, TCP is a connection-oriented protocol and provisions the reliable communication with various features.
On the other hand, the UDP is a very simple connection-less real-time transport protocol that offers a fast communication process than TCP but is unreliable as it is not supported by any acknowledgment process of data receiving and sending.
However, both are important and have significance in their ways.