As an example, suppose I have a 'smart' thermometer that broadcasts the current temperature as a UDP datagram every N seconds.
Now, I can write a client that listens for those messages and displays them graphically, and I can have that client running on multiple computers simultaneously. No problem so far.
But, when I try to run two instances of the client on the same Windows computer, I get errors about attempting to "bind to a port already in use".
Is this:-
If A or B, is there any way round it.
If C, then I'll post some code..
On Windows you can have multiple processes bind to the same socket by using the
SocketOptionName.ReuseAddress
option (see this answer Is there a way for multiple processes to share a listening socket?). Broadcasting a packet should force Windows to give a copy of that packet to each listener on that end-point.
In answer to Roddy, yes, SO_REUSEADDR works this way on *nix too.
For in-depth answer, refer to https://stackoverflow.com/a/14388707/705086.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With