0

I have a program that listens for multicasts and I'd like it to be able to share a port with other instances of the same program, so that if I have 3 instances running on the same host, they can all share the same port.

Is it possible to do this, would it involve setsockopt and SO_REUSEADDR?

EDIT: I am going off of this site for my code, the only thing I've changed is what is sent in the message.

Kara
  • 6,115
  • 16
  • 50
  • 57
wolf
  • 127
  • 7
  • 1
    Sounds similar to this question: http://stackoverflow.com/questions/1694144/can-two-applications-listen-to-the-same-port – Santa Nov 14 '13 at 21:47
  • @Santa That is much more information than I could hope to google on my own, thanks! – wolf Nov 15 '13 at 16:44

1 Answers1

1

setsockopt was what I needed, here is an example of what I did:

in the declarations:

int yes = 1;

then before the call to bind() i called setsockopt()

setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));

this now allows me to run multiple instances of the program on the same machine, listening for multicasts on the same port.

wolf
  • 127
  • 7
  • @RemyLebeau Mutlicasts are sent to an IP:port just like anything else. You won't receive multicasts sent to a different port. – user207421 Nov 14 '13 at 23:07