Open In App

How Applications Coexist Over TCP and UDP?

Last Updated : 19 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The Transport layer takes data from the Application layer, then it breaks into small segments called packets. Then handles them to the Network Layer for delivery. The transport layer uses two protocols which will be discussed here in this article. They are TCP ( Transmission Control Protocol ) and UDP ( User Datagram Protocol ).

TCP ( Transmission Control Protocol ): It is a transport protocol that is used on top of IP to ensure reliable packet transmission from source to destination. It takes data from the application layer then divides the data into packets and provides each packet with numbering. It establishes the connection between devices in a network before communication can take place.

Header size: 20 bytes

Advantages: 

  1. 100% delivery rate: TCP ensures that your packets are delivered by guaranteeing a connection-oriented reliable service. This means that any lost packets will be re-sent.
  2. Error-free: It detects errors using checksum verification.
  3. Sequence Delivery: Packets will be delivered in order

Disadvantages:

  1. Slower: Data transfer rate is slower than UDP (User Datagram Protocol ).
  2. Broadcasting is not supported.
  3. Slow Handshake: TCP will perform a handshake between the sender and the receiver when a connection is established. This may take time.

Examples of TCP:  File Transfer Protocol (FTP), E-mail (SMTP TCP), and the World Wide Web are all examples of TCP.

Diagram for a better understanding of TCP and UDP :

TCP-UDP

TCP-UDP

UDP (User Datagram Protocol ): It is a Transport Layer Protocol that is part of the Internet Protocol Suite and an alternative to TCP. UDP does not even need a connection before data transfer. It is also known as the “fire-and-forget” protocol because it sends data regardless of whether it is received or not.

Header size: 8 bytes

Advantages:

  1. Speed: Faster than TCP because no guarantee of data packet delivery.
  2. Connectionless: There is no need to connect the source and destination before transmitting data.
  3. Error Detection: It employs checksums with all packets to detect errors.

Disadvantages :

  1. There is no congestion control or acknowledgment of received data.
  2. It is only concerned with sending data.
  3. Unreliable: There is no method to ensure data is received in the same order as it was sent. 

Examples of UDP: Voice over IP (VoIP), online multiplayer games, streaming media applications such as movies, and Domain Name Systems (DNS) are all examples of UDP.

Can an application use both TCP and UDP at the same time?

Yes. Nothing prevents you from using as many networking protocols as required unless they are not made to run on the same socket simultaneously.

How Do Applications Coexist Over TCP and UDP?

Applications can coexist over both TCP and UDP by implementing functions to handle errors, flow control, and data re-transmission. If TCP and UDP are to be used in a single application, two sockets must be created and each of them must be bound to a network interface. This can be done by first opening a socket and binding it to a particular IP address and port. To achieve this, the socket() function will be used. This function accepts two arguments which are the type of socket and the address family. After creating the sockets, we will have to bind them to a hostname or IP address using the bind() function. This function accepts a single argument that is the socket to bind. TCP can be used for some specific tasks and UDP for other tasks in a single application. Wherever they can be utilized efficiently, they are used accordingly. 

Example : 

  • DNS is an application layer protocol that uses both TCP and UDP on a well-known port to provide a variety of services.
  • UDP is a protocol that optimizes the transmission of small data packets. If the size of the response message is under 512 bytes, UDP might be the best option because it only has a limitation of 512-byte packet size.
  • A TCP connection is used if the size of the response message exceeds 512 bytes.
  • If a client does not receive a response from DNS after 3 to 5 seconds, it must re-transmit the data using TCP.
  • DNS employs UDP and TCP for name queries and zone transfer respectively.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads