This is in Java, but if necessary, I can always return to C through JNI.
I have a system with two network adapters, each of which is connected to a separate subnet. I want to use multicast (specifically SDP) to discover other hosts on both networks.
One network is simple: create a MulticastSocket on the specified port, joinGroup it, and I get the packets. Simplicity.
Two networks: not yet possible. I tried:
1) create two sockets, bind to the same port and use setInterface () or setNetworkInterface () to "connect" to the correct interface. No luck, even after various permutations of setReuseAddress ().
2) create one socket and then try to join twice, with two calls to joinGroup (SocketAddress mcastaddr, NetworkInterface netIf). The second connection call fails.
Solutions outside of Java would be great. In particular, if I could configure multicast routes that would effectively “combine” the two interfaces (I could then look at each packet to determine which network), which would be nice. As I mentioned earlier, in this environment you can use any amount of embedded code (Linux, with the java Apache "luni" infrastructure).
Thanks!
source share