For an concrete example lets assume that there are 2 mcast IPs (ip1, ip2) on same port port. I want to run two different processes, one listening to ip1 (and not ip2) and other listening to ip2(and not ip1). So I called bind with (ip1,port), and (ip2,port) in other process, rather than ((INADDR_ANY, port).
That works fine in principle, but let's say there are not 2 ips but 100 IPs then I end up creating 100 UDP sockets and now my process is not able to handle this well, I am seeing a lot of packet drops.
Basically if I simply bind to (INADDR_ANY, port) and then multicast join 50 IPs it works fine but if I create 50 different sockets then it doesn't.
Is it expected? Are socket with wildcard bind more efficient than specific address ones OR performance drop is because now there are so many sockets and now select and polling thing takes a lot of time?
Is there some way that I don't need to create so many sockets and processes also don't get other process's data?
Asked
Active
Viewed 1,486 times
0

user207421
- 305,947
- 44
- 307
- 483

user3036846
- 11
- 4
-
possible duplicate of [Receving multiple multicast feeds on the same port - C, Linux](http://stackoverflow.com/questions/2741611/receving-multiple-multicast-feeds-on-the-same-port-c-linux) – mpromonet Jun 20 '14 at 21:17
1 Answers
0
I guess that you decide to use the bind workaround because you are using Linux that have a different behavior compare to others OS like FreeBSD or Windows (see https://bugzilla.redhat.com/show_bug.cgi?id=231899)
With modern kernel (since 2.6.31) it is possible to ask to receive only the subscribed multicast groups reseting the IP_MULTICAST_ALL option (see manpage ip(7) ) :
int mc_all = 0;
if ((setsockopt(sock, IPPROTO_IP, IP_MULTICAST_ALL, (void*) &mc_all, sizeof(mc_all))) < 0) {
perror("setsockopt() failed");
}
I never experienced that binding impact socket performance, nevertheless you can try this option and bind on INADDR_ANY. Perhaps it will help your performance ?

mpromonet
- 11,326
- 43
- 62
- 91