User Datagram Protocol : IOT Part 30 | EngineersGarage
Close or Esc Key

Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

User Datagram Protocol : IOT Part 30

Written By: 

Priya
The TCP/IP protocol despite being most common protocol stack on internet is not much suitable for IoT applications due to large overhead. It is more suitable for applications where reliable delivery of data with high bandwidth in hand is required. The IoT applications generally have limited bandwidth and need swift transfer of small data packets. In such case, the UDP/IP stack is far better than TCP/IP.  
 
The User Datagram Protocol (UDP) is the simplest transportation layer protocol used primarily for establishing low-latency and loss tolerating connections between applications on the communication network. Both TCP and UDP run on the top of Internet Protocol (IP) that is why they are referred as TCP/IP and UDP/IP. 
 
User Datagram Protocol (UDP)
 
UDP is a connectionless protocol which means the sender just transmits the data without waiting for the connection with the receiver. It is an unreliable protocol when compared with TCP. There is no error checking mechanism or correcting mechanism involved in data transmission which results in using less bandwidth. UDP protocol just sends the packets (or datagram). There is no acknowledgement guarantee of packet received by the other end. It allows for less data overhead and delays. 
 
To achieve higher performance, the protocol allows individual packets to be dropped (with no retries) and UDP packets to be received in a different order than they were sent, as dictated by the application.
 
Features of UDP - 
 
The UDP protocol stack has the following features - 
 
1) UDP can be used when acknowledgement of data does not hold any significance.
 
2) It is great for data flowing in one direction.
 
3) It is connectionless protocol. 
 
4) It does not provide any congestion control mechanism.
 
5) It is a suitable protocol for streaming applications such as video conference applications, computer games etc.
 
UDP Datagrams -
 
UDP traffic works through packets called datagram, with every datagram consisting of a single message unit. The header details are stored in the first eight bytes, but the rest is what holds onto the actual message. The UDP datagram header can be divided into four parts each of which is two bytes long. These parts are as follow - 
 
1) Source Port - This 16 bits (2 bytes) information is used to identify the sender port which will send the data. A valid UDP port number ranges from 0 to 65535. 
 
2) Destination Port - This 16 bits information is used to identify the receiver’s port on which the data will be received. A valid UDP port number ranges from 0 to 65535. This field identifies the receiver's port and is required.
 
3) Length - The length field specifies the entire length of the UDP packet (UDP header and UDP data). This individual field is 16-bits field. The minimum length of the Length field is 8 bytes in case of no UDP data.
 
4) Checksum  - This field stores the checksum value generated by the sender before sending the data to the receiver. UDP checksums protect message data from being corrupted. The checksum value represents an encoding of the datagram data calculated first by the sender and later by the receiver. In UDP, checksum is optional, as opposed to TCP where checksum is mandatory.
 
Advantages of UDP - 
 
The UDP/IP has the following advantages over TCP/IP stack - 
 
1) It is better than TCP for applications that require constant data flow, bulk data and which require more swiftness than reliability.
 
2) For multicast and broadcast purposes, UDP is best suited because it supports point to multipoint transmission method. The sender does not need to keep track of retransmission of data for multiple receivers in contrast with the TCP/IP where sender needs to take care of each packet.
 
3) There is small packet header overhead in UDP (only 8 bytes) whereas TCP has 20 bytes of header.
 
In the next tutorial - Client Server Communication over UDP Protocol, an ESP8266 module is configured as UDP server and a laptop is configured as UDP Client. The UDP Client sends some data to the server and the server acknowledges it by switching an LED on. 
 
]]>]]>