简体   繁体   中英

Multicast listening on same host and port in C

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM