Решение, которое я нашел, состоит в том, чтобы выполнить итерацию по всем интерфейсам и протестировать включенное соединение: Пример рабочего кода:
public static DatagramChannel openDatagramChannelForAnyWorkingInterface(int port, String ip) throws IOException {
DatagramChannel channel;
try {
channel = DatagramChannel.open(StandardProtocolFamily.INET);
channel.configureBlocking(true);
channel.socket().setReuseAddress(true);
channel.bind(new InetSocketAddress(port));
Enumeration<NetworkInterface> networkInterfaceEnumeration = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface np : Collections.list(networkInterfaceEnumeration)) {
try {
channel.join(InetAddress.getByName(ip), NetworkInterface.getByName(np.getName()));
log.info("Data joining channel ip [{}], port [{}] interface [{}]", ip, port, np.getName());
break;
} catch (Exception ignore) {
}
}
} catch (Exception e) {
log.error("Exception while subscribing to market data: ", e);
throw e;
}
return channel;
}