Is it possible for two or more programs to monitor UDP packages on a single port? We have a device that converts RS-232 data to UDP on port 55110, but it appears I can only have one listener running on a given computer. Attempts at a second cause "Address already in use". Apparently there is some other program on the computer listening, because REUSE => 1 doesn't help. Multiple users would like to sample the data. I apologize for so basic a question.
It is possible for two programs to listen on the same UDP port, but both programs have to specify that they want to allow the port to be shared. Here is an excerpt from my code that tells the OS to do this (called just before calling bind() on the UDP socket):
if (allowShared)
{
const int trueValue = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &trueValue, sizeof(trueValue));
#ifdef __APPLE__ // MacOS/X requires an additional call also
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &trueValue, sizeof(trueValue));
#endif
}
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