The protocols TCP and UDP are the two TCP/IP transport layer protocols. There exist some similarities and dissimilarities between the Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). One of the differences is that TCP is a connection-oriented protocol as it establishes an end to end connection between computers before transferring the data. On the other hand, UDP is a connection-less protocol since it does not determine the connection before sending data. The TCP and UDP protocol present in the Transport Layer of TCP/IP Model.
When we ponder over the layer 3 protocols which work on IP, these are connectionless, unacknowledged and unreliable. Therefore, it would not be possible to provide the guaranteed delivery of the data. This emerged the need for the TCP and UDP protocol, which facilitate the automatic management and deals with the problems like congestion control and flow control.
However, designers also thought to build these abilities directly into the IP as it was before when there was just a single protocol TCP, but all these features were provided at the cost of time and bandwidth. The better solution was to define the two protocols at the transport layer and let the network layer (IP) to take care of elementary data movement on the internetwork.
Thence, the TCP and UDP protocols were developed among which TCP intended to provide a rich set of services or the applications that require those functionalities, which would require some amount of overhead for using it. While the main purpose of UDP was to provide some sort of layer 4 functions but in a simple, easy to use and fast way.
Content: TCP Vs UDP
|Basis for Comparison||TCP||UDP|
|Meaning ||TCP establishes a connection between the computers before transmitting the data||UDP sends the data directly to the destination computer without checking whether the system is ready to receive or not|
|Expands to||Transmission Control Protocol||User Datagram Protocol|
|Connection Type||Connection Oriented ||Connection Less|
|Header Size||20 Bytes ||8 Bytes|
|Acknowledgement||It takes acknowledgement of data and has the ability to retransmit if the user requests.||It neither takes acknowledgement, nor it retransmits the lost data.|
|Protocol connection setup||Connection-oriented, the connection must be established prior to transmission||Connectionless, data is sent without setup|
|Data interface to the application||Stream-based||Message-based|
|Retransmissions||Delivery of all data is managed||Not performed|
|Features provided to manage the flow of data||Flow control using sliding window protocol||None|
|Overheads||Low but greater than the UDP||Very low|
|Data quantity suitability||Small to moderate amounts of data||Small to enormous amounts of the data|
|Implemented over||Applications where reliable transmission of data matters.||Application where data delivery speed matters.|
|Applications and protocols||FTP, Telnet, SMTP, IMAP etcetera.||DNS, BOOTP, DHCP, TFTP etcetera.|
Definition Of TCP
TCP or Transmission Control Protocol is a connection-oriented protocol, found in the transport layer of the TCP/ IP Model. It establishes a connection between source and destination computer before starting the communication.TCP is highly reliable, as it uses the 3-way handshake, flow, error and congestion control. It makes sure that the data sent from the source computer are received accurately by the destination computer. If in case, data received is not in the proper format, then TCP retransmits the data. In TCP, transmissions are handled using the sliding window system which helps in detecting the acknowledged transmission and automatically retransmit it.
Functions performed by TCP
- Addressing/multiplexing – Higher-layer application processes are determined through using TCP ports. This layer mainly multiplexes the data received from the various processes and sends data with the help of the underlying network layer protocol.
- Establishing, managing and terminating connections – There are a group of procedures which are followed by the devices to set up a connection through which data can travel. Once the connection is established, it is needed to manage, and at last, after finishing the TCP connection, it is terminated.
- Handling and packaging data – This feature provides a mechanism which enables the data to be sent to TCP from higher layers, which is then packaged into the message to send it to the destination TCP software further. The software residing at the receiving end unpackages the data and supply it to the application on the destination machine.
- Transferring data – In this step, the packaged data is transferred to the TCP process on the other devices through following the layering principle.
- Providing reliability and transmission quality services – It involves the services and features that permits an application to consider the protocol a reliable medium of transferring the data.
- Providing flow control and congestion avoidance features – This feature controls the flow of the data between the two devices and deals with the congestion.
Following protocols use TCP for transmitting data:
- HTTP(Hypertext Transfer Protocol),
- HTTPs(Hypertext Transfer Protocol Secure),
- FTP(File Transfer Protocol),
- SMTP(Simple Mail Transfer Protocol), etc.
Definition Of UDP
UDP or User Datagram Protocol is a connectionless protocol found in the transport layer of TCP/IP Model. It neither establishes a connection nor checks whether the destination computer is ready to receive or not; it just sends the data directly. UDP is used to transfer the data at a faster rate. It is less reliable and so used for transmitting data such as audio and video files.
UDP neither guarantees the delivery of data, nor does it retransmits the lost packets. It is just a wrapper protocol that facilitates application in accessing the IP.
Functions performed by UDP
The main task of a UDP is to take data from the Higher-layer protocols and position it in UDP messages, which is then moved to the IP for transmission. It follows some specific steps to transmit the data which are given below.
- Higher-Layer Data Transfer – In this step, a message is sent to the UDP software by an application.
- UDP Message Encapsulation – It includes the encapsulation of the message into the Data field. The headers of the UDP message along with the source port field and destination port field, are added. It also computes the checksum value.
- Transfer message to IP – At last the UDP message is transferred to the IP for transmission.
Similarly, when the destination end receives the message, this whole process gets reversed.
Following protocols use UDP for transmitting data:
- BOOTP(Bootstrap Protocol),
- DHCP(Dynamic Host Configuration Protocol),
- DNS(Domain Name Server),
- TFTP(Trivial File Transfer Protocol), etc.
Key Differences Between TCP and UDP
- TCP is Connection-oriented whereas, UDP is Connectionless protocol.
- TCP is highly reliable for transferring useful data as it takes the acknowledgement of information sent. Also, resends the lost packets if any. Whereas in the case of UDP if the packet is lost it won’t request for retransmission and the destination computer receives corrupt data. So, UDP is an unreliable protocol.
- TCP is slower as compared to UDP since TCP establishes the connection before transmitting data, and ensures the proper delivery of packets. On the other hand, UDP does not acknowledge whether the data transmitted is received or not.
- Header size of UDP is 8 bytes, and that of TCP is more than double. TCP header size is 20 bytes since, and TCP header contains options, padding, checksum, flags, data offset, acknowledgement number, sequence number, source and destination ports, etc.
- Both TCP and UDP can check for errors, but only TCP can correct the error since it has both congestion and flow control.
Both TCP and UDP have their advantages and disadvantages. UDP is faster, simpler and efficient and hence generally used for sending audio, video files. TCP, on the other hand, is robust, reliable and guarantees the delivery of packets in the same order.
Hence, we conclude that both TCP and UDP are essential for data transmission.