C Program for File Transfer Using UDP

Learn via video courses
Topics Covered

Overview

UDP is an unreliable protocol. It does not create a dedicated path for transmitting packets. So it is a connectionless protocol. Its header size is very small i.e. 8 bytes only.

What is UDP?

User Datagram Protocol is abbreviated as UDP. UDP works on the transport layer. UDP is a connectionless and unreliable protocol. There is no need to create a dedicated path for the transmission of data. UDP also sets some rules that decide how data needs to be transferred to the network using the internet. It transfers the packet in encapsulated form i.e. combining all the data in a packet and also provides its header details to the particular packet in the network.

UDP Header

UDP Header The size of the UDP header is very small i.e. 8 bytes only. These 8 bytes have four fields, and the length of each byte is 2 bytes.

Given below there is a detailed explanation of the function and purpose of each field of the UDP header.

Source port: Source port is useful for the identification of the application that is transferring the data.

Destination port: Destination port is useful for the identification of the application that is receiving the data.

Length: For finding out the length of the header itself, the length field is used.

Checksum: There may be the chance that corrupted data will be delivered in the network so for checking whether the data transfer is corrupted or not, checksum is used.

UDP File Transfer Tools and Projects

  • Quick UDP Internet Connections abbreviated as QUIC. It is designed by Google and it is an experimental network protocol. It replaced http/2 for providing internet browsing in proper time and also even faster is the main objective of using QUIC.
  • The extended form of UDP transfer protocol is UDT. UDT is used whenever there is a need to send data in large amounts. As it transfers data very fast as compared to TCP. Configurable is one of the main features of UDT and it allows the usage of different algorithms that control congestion.
  • TCP and UDP blend in a tsunami. For achieving a faster speed it prefers to use UPD to transfer the data and TCP for control purposes.
  • For transferring and receiving the TCP and the UDP packets, packetsender is useful. It can also be used for many purposes such as malware analysis, test automation, quality assurance, etc. It comes along with GUI.
  • UFTP is based on FTP with multicast. It is an encryption form of UDP. Files can be transferred securely, efficiently, and reliably using UFTP.

Algorithm

  1. Server waits for the filename after starting
  2. Filename is sent by the client.
  3. Filename is received by the server which is sent by the client. The server starts reading the content of the file if the file is present and until the server reaches the End Of File, it continues sending the buffer which is filled with the encrypted file content.
  4. EOF represents End Of File.
  5. File is received at the client side in the form of a buffer until EOF(End Of File) is reached. Then the decryption is done.
  6. Server sends a file not found to the client if the file is not present.

UDP File Transfer Server

Code

Output

UDP File Transfer Client

Code

Output

UDP vs TCP

FEATURESUDPTCP
ReliabilityIt is unreliable as there is no assurance of receiving all the packets.It is very reliable as it acknowledges each packet and tracks each packet till it reaches its destination.
Data flowFlow control functionality is not available in UDP.It provides flow control methods like sliding windows, congestion avoidance, etc.
Transmission speedData transfers speedily in UDP.It is not so fast as compared to TCP.
HeaderSize of the header is very small i.e. 8 bytes.Size of the header is small but as small as compared to UDP. Its header size is 20 bytes.
ConnectionIt is absolutely connectionless. It does not need to create a dedicated connection for the transmission of data.It is connection-oriented as it requires a proper and dedicated connection for the transmission of data.
AcknowledgementThere is no need for acknowledgment of the packet.It is mandatory to acknowledge the packet as further transmission is possible only after the acknowledgment of the previous packet.
ProtocolsDNS, VoIP, DHCP are some protocols that use UDP.HTTP, HTTPS, and FTP are some protocols that use TCP.

Conclusion

  • UDP is a connectionless and unreliable protocol.
  • UDP transfers messages very fast.
  • The size of the UDP header is 8 bytes.
  • The UDP header has four fields, each of 2 bytes.
  • Fields of UDP header are source port, destination port, length, and checksum.
  • Some UDP file transfer tools and projects are UDT, QUIC, tsunami, Packet sender, and UFTP.