Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024
Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM
Computer Networks

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.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Comparison: TCP and UDP

Comparison: TCP and UDP

Also see, Difference Between Compiler and Interpreter and Assembler

Frequently Asked Questions

List all layers of the TCP/IP model?

There are seven layers in the OSI model. They are:
Physical layer
Data link layer
Network layer
Transport layer
Application layer

What is the Simplex mode?

The communication is unidirectional in Simplex mode. Only one of the devices on a link can be a sender, and the other can only receive.

What is Half-duplex and Full-duplex mode?

Both the devices can act as a sender or receiver in half-duplex mode. But at a time, only one device can transmit data over the link.
Full-duplex mode is bi-directional, i.e. both devices can send or receive data at the same time.

List most common network topologies?

Some of the most common network topologies are:
Mesh topology
Bus topology
Star topology
Ring topology

Conclusion

Cheers if you reached here!! 

In this article, we discussed the differences between TCP & UDP, protocols used by the transport layer. 

Recommended Readings:


Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Topics covered
1.
Introduction
2.
TCP & UDP protocols
2.1.
Example
3.
Comparison: TCP and UDP
4.
Frequently Asked Questions
4.1.
List all layers of the TCP/IP model?
4.2.
What is the Simplex mode?
4.3.
What is Half-duplex and Full-duplex mode?
4.4.
List most common network topologies?
5.
Conclusion