DatagramSocket Port Re-use, how is it supposed to work?

Hi All,

I’m trying to achieve having multiple instances of the same app receive the same UDP data on localhost : 60000.
I’m under the impression that when you bind a DatagramSocket to a ip and port, and call setEnablePortReuse(true), that this socket should be able to share this port with other applications and receive data on all instances of the bound port.
After building a test-app, this does not seem to be the case: the latest instance “steals” the port from the previously started application and only this instance receives incoming messages.

Is there any way to achieve receiving the same data on all socket instances?

More than one process may bind to the same SOCK_DGRAM UDP port if the bind()
is preceded by:

	int one = 1;
	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))

In this case, every incoming multicast or broadcast UDP datagram destined to
the shared port is delivered to all sockets bound to the port.  For backwards
unicast datagrams are never delivered to more than one socket, regardless of
how many sockets are bound to the datagrams destination port. 

You will either need to use multicast or broadcast or come up with a different system.

Thanks G-Mon. Unfortunately the system is already in place. There is a possible workaround, but I’d rather not take it. Broadcasting won’t work since loopback doesn’t support it. The multicast-route seems worth exploring. Although I’m not quite sure how that would work on the loopback interface.