Introduction
This blog will compare the TCP & UDP protocols in different aspects. Both these protocols are used in the Transport layer. The primary function of the transport layer is to ensure process-to-process data transmission, i.e., to ensure error-free & reliable transfer of data from a program on one host to the program on the other host. We will discuss the difference between the protocols used by the transport layer.
Also read, Basic Networking Commands
TCP & UDP protocols
TCP stands for Transmission control protocol. TCP is a connection-oriented protocol, meaning that there should be a connection between the two communicating devices before the data is transmitted. And this connection should be closed only after the data is transmitted. The TCP connection is established using a three-way handshake. This protocol offers flow-control and robust error-control services in the transport layer. TCP protocol ensures reliable transmission of data.
UDP stands for User datagram protocol. UDP is a connectionless protocol. It does not guarantee reliable and error-free transfer of data. But since this protocol does not involve the overhead of error-checking and correction, this protocol is faster and more efficient than the TCP protocol.
However, both protocols are process-to-process protocols.
Example
Consider a simple example to understand the fundamental difference between TCP & UDP protocols:
Assume two buildings, A and B. And there is a river between them. The goal is to send a letter from building A to building B. Now there are two ways to accomplish this
Method 1: Build a bridge over the river and deliver the letter.
Method 2: Use a pigeon to deliver the letter.
Here, method 1 is TCP protocol where a connection is built(bridge in this example) between the two devices and then transmitted the data(letter).
Method 1 is reliable because we can directly reach the other end without any error in or loss of data.
Here method 2 is UDP as no connection is required to transmit the data(letter). UDP is faster than TCP, but it is not reliable. Because it is not guaranteed that the pigeon will go to the correct destination, the letter can be lost by the pigeon.
Must Read Stop and Wait Protocol.
You can read related articles such as Congestion Control in Computer Networks here.