18

I know that UDP is inherently unreliable, but when connecting to localhost I would expect the kernel handles the connection differently since everything can be handled internally. So in this special case, is UDP considered a reliable protocol, or will the kernel still potentially junk some packets if buffers are overrun?

Bryan Ward
  • 6,443
  • 8
  • 37
  • 48
  • 3
    Besides what TomMD said, I'd wonder why you're using UDP in the first place. TCP's few disadvantages are essentially immaterial when it comes to localhost usage. The only real gain you'd get from UDP would be a very slight loss of overhead, most of which goes away if you have to make it reliable yourself anyway. – Nicholas Knight Jun 14 '10 at 02:26
  • 8
    well, UDP lets you broadcast to arbitrary unknown clients... – Michael Jan 16 '14 at 23:40
  • 1
    Does this answer your question? [What would cause UDP packets to be dropped when being sent to localhost?](https://stackoverflow.com/questions/7968566/what-would-cause-udp-packets-to-be-dropped-when-being-sent-to-localhost) – Dave Jarvis Jan 06 '20 at 22:57

3 Answers3

11

I have seen UDP to localhost dropping packets. We think we were overloading the kernel queue. All we know for sure is that it was dropping packets.

Alan
  • 111
  • 1
  • 3
10

I repeat a previous answer to a related question. To remain portable always anticipate your UDP sockets might drop packets or receive out of order data.

Community
  • 1
  • 1
Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
  • 2
    out of order data is definitly a thing on localhost, I have been playing round with a multiprocess logger using udp, and it is relativly common (I was using node.js for both sender and reciever), I havent experienced any dropped packets yet, so that is less common, but havent sent enough packets to know exactly how uncommon it is, but it definitly isnt 100% reliable, or even 99%. – Reed Thorngag Jan 13 '23 at 04:38
4

I don't think that UDP (or any other network protocol) says anything about different behavior when connecting to localhost. So the answer will depend on the specific kernel that you're using. Best to assume that UDP will behave like UDP.

Mike Baranczak
  • 8,291
  • 8
  • 47
  • 71