Is it possible to receive data from more than one multicast group on a single socket?
For example:
void AddGroup(int sock,
const char*
You only bind a socket once. Skip the bind the second time and see what happens.
Yes, it's possible: look on the example in the link (http://www.tenouk.com/Module41c.html) To shorten this up in a few steps:
You can join as many multicast groups as you like, using the appropriate setsockopt()
call with the IP_ADD_MEMBERSHIP option, rather than bind().
In unix based OSes:
If you need to bind to multicast address, you cannot call bind()
more than once. And you will need to bind to multicast address when you expect more than one multicast streams using same destination port and multiple processes running in same device receiving those multicasts.
For example, when you have multicast streams: 239.0.0.1:1234, 239.0.0.2:1234, 239.0.0.3:1234 and 239.0.0.4:1234, and you want to receive 239.0.0.1, 239.0.0.2 in process-A and want to receive 239.0.0.3, 239.0.0.4 in process-B, you cannot accomplish this when both processes A and B running in same device.
You can join as many multicast groups you want to on a single socket. See setsockopt(), IP_PKTINFO for a way to recognize which multicast group you are reading data from.
bind
to the passive address, i.e. 0.0.0.0 for IPv4 and use ASM or SSM to pull in additional groups, e.g. IP_ADD_MEMBERSHIP
as listed.
You can only bind
once.