简体   繁体   中英

UDP Multicast server adding Clients to Multicast Group

I have a C Project to implement Multicast in C language, Here server(only one) sends data,and clients receive data sent by server( multiple).

Here The issue is, I want the server to Clients to Multicast Group.

mreq.imr_multiaddr.s_addr = mcastAddr.s_addr;
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
rc = setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(void *) &mreq, sizeof(mreq) );

The above thing is used to add client to Multicast group from client side.

Is there a way to add client to group from server? I think getting socket of client and adding it to group doesn't make sense to me, Is it Possible.

Any help appreciated, Thanks in advance.

A multicast sender can't make a receiver listen to a multicast address, at least not directly. The code above tells the machine it runs on to start listening on a specific multicast address on a specific interface.

If you want a server to tell a client to join a group, you would need to send a separate unicast message in an application specific manner that tells the client to join the group, then when the client receives the message it would join the group using the code above.

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