Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is UDP always unreliable?

Tags:

sockets

udp

I'm about to re-architect a real-time system that has been prototyped on a single node and specify how it should be scaled up to multiple nodes (probably never more than 20 of them in any one LAN). Some of the functionality will multiply on a per-node basis, and some of it will remain centralised on a one-per-system basis. There is going to be a need for communication between each node and that central unit (possibly a master node), but not between individual nodes.

Due to the real-time demands of the system, UDP is something that should be considered for that communication. But... it is almost always described as unreliable. Is this always the case? Does it not depend on the scale of the network, the data load on the network and the way the protocol is used?

For example, suppose I have a central unit which regularly polls through each node by addressing a UDP message to it, and each node immediately responds with its data via UDP. There is no other communication on the (isolated) network. Suppose there is also some mechanism to ensure there are never any collisions (e.g. all nodes have a maximum transmission length for their responses to a poll message, and the latencies are nailed down to known levels). Is there any (hidden) reason in a simple and structured network like this that you would ever fail to transmit/receive every last UDP packet and have near 100% reliability?

EDIT: the detail of this question suffers from confusion around what "unreliable" means, and whether it is intended to apply only to UDP, or to the system in which UDP is employed. I have chosen to leave this confusion in the question, because looking back over a lot of material on UDP, I can see that this confusion might be very common, and that answers which highlight that confusion and overcome it might be valuable.

like image 791
omatai Avatar asked Dec 15 '22 18:12

omatai


1 Answers

The key is, UDP does not make any guarantees. There are many reasons why datagrams might go undelivered:

  • Sender host buffers fill up
  • Cosmic rays flip bits somewhere along the way, causing a checksum mismatch and the datagram to be discarded
  • Electromagnetic interference corrupts the signal momentarily
  • A network cable gets unplugged for a moment
  • A hub or switch loses power for a moment
  • A switch's buffers fill up
  • Receiving host buffers fill up

If any of these things (or many others) occurs, a datagram may go undelivered. UDP will make no attempt to detect this or to re-deliver it.

like image 82
nobody Avatar answered Jan 10 '23 15:01

nobody