Reputation: 2684
I am trying to subscribe to a particular market data feed, distributed by multicast via FAST protocol. In Java, there is MulticastSocket
and there is DatagramChannel
supporting multicast.
The FAST protocol library I use, OpenFAST, accepts MulticastSocket
instances to create endpoints, but it seems to be impossible to specify source IP address in its configuration, it binds to "any source", which doesn't work with this market data feed. It is possible (since Java 1.7) to create a DatagramChannel
with source IP defined, like described here:
NetworkInterface interf = NetworkInterface.getByName("eth0");
InetAddress group = InetAddress.getByName("225.0.0.100");
InetAddress source = InetAddress.getByName("172.20.40.1");
DatagramChannel dc = DatagramChannel.open(ProtocolFamily.INET)
.setOption(SocketOption.SO_REUSEADDR, true)
.bind(new InetSocketAddress(5000))
.setOption(SocketOption.IP_MULTICAST_IF, interf);
MembershipKey key = dc.join(group, interf, source); // <- source specified
However, I don't see a way to get a MulticastSocket
from channel, the socket()
method returns just the plain old DatagramSocket
.
Is there a way to create a MulticastSocket
with source filtering enabled, either directly or from DatagramChannel
?
Upvotes: 3
Views: 1712
Reputation: 84169
java.nio.MulticastChannel
implements source-specific multicast, which is only available in IGMPv3. java.net.MulticastSocket
, on the other hand, only supports IGMPv2, so you are out of luck here.
I would suggest you filter unneeded multicast sources out at the firewall level, but you can also try DatagramSocket.connect()
to establish source filtering in the app.
Hope this helps.
Upvotes: 2