1

I have two applications, one is C-Based, one is NodeJs-Based. Two apps need process UDP message from same port in one Centos machine. Is it possible to have 2 programs that bind to same UDP port and take message simultaneously?

In NodeJs, I used dgram:

dgram.createSocket({type: "udp4", reuseAddr: true})

And in C, I use SO_REUSEADDR, SO_REUSEPORT parameter for the setting socket.

The problem is: I can not receive any UDP message in application started later. That means only one application can receive UDP message. Any help is really appreciated. Thanks

danglingpointer
  • 4,708
  • 3
  • 24
  • 42
hoang
  • 1,444
  • 11
  • 19
  • 1
    Go through this link : [enter link description here](https://stackoverflow.com/questions/4364434/let-two-udp-servers-listen-on-the-same-port) – Kanji Viroja Jun 08 '17 at 16:23

1 Answers1

2

Using SO_REUSEADDR or SO_REUSEPORT on a UDP socket only work for incoming multicast or broadcast packets.

If a unicast packet comes in, whether it is delivered to all sockets or just one (and which one) is implementation defined.

dbush
  • 205,898
  • 23
  • 218
  • 273
  • Actually, with `SO_REUSEPORT` it is well defined -- each incoming packet is delivered to exactly one listening socket. It is designed for load balancing, but that is apparently not the behavior the OP wants. – Chris Dodd Jun 08 '17 at 17:28
  • @ChrisDodd Can you please provide a reference? I can't find this in man page of socket or [here](https://lwn.net/Articles/542629/) – zardosht Nov 18 '20 at 13:58