private static final Channel createChannel(String address, int port, String bindAddress) {
//create a channel
GroupChannel channel = new GroupChannel();
McastService mcastService = (McastService)channel.getMembershipService();
mcastService.setPort(port);
mcastService.setAddress(address);
// REVIEW: In my case, there are multiple IP addresses
// One for the WIFI and the other one for VPN. For some reason the VPN one doesn't support
// Multicast
/*
try {
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
while (nis.hasMoreElements()) {
NetworkInterface ni = nis.nextElement();
if (ni.isLoopback() || !ni.isUp() || !ni.supportsMulticast()) {
continue;
}
Enumeration<InetAddress> ips = ni.getInetAddresses();
while (ips.hasMoreElements()) {
InetAddress addr = ips.nextElement();
System.out.println(addr.getHostAddress());
}
}
} catch (SocketException e) {
e.printStackTrace();
}
*/
if (bindAddress != null) {
mcastService.setBind(bindAddress);
}
// mcastService.setBind("192.168.1.100");
return channel;
}