/** * Check whether the given address' interface supports multicast * * @param pAddr address to check * @return true if the underlying networkinterface is up and supports multicast * @throws SocketException */ public static boolean isMulticastSupported(InetAddress pAddr) throws SocketException { return isMulticastSupported(NetworkInterface.getByInetAddress(pAddr)); }
/** * Get a local address which supports multicast. A loopback adress is returned, but only if not * another is available * * @return a multicast enabled address of null if none could be found * @throws UnknownHostException * @throws SocketException */ public static InetAddress getLocalAddressWithMulticast() throws UnknownHostException, SocketException { InetAddress addr = InetAddress.getLocalHost(); NetworkInterface nif = NetworkInterface.getByInetAddress(addr); if (addr.isLoopbackAddress() || addr instanceof Inet6Address || !isMulticastSupported(nif)) { // Find local address that isn't a loopback address InetAddress lookedUpAddr = findLocalAddressViaNetworkInterface(); // If a local, multicast enabled address can be found, use it. Otherwise // we are using the local address, which might not be what you want if (lookedUpAddr != null) { return lookedUpAddr; } addr = InetAddress.getByName("127.0.0.1"); } if (isMulticastSupported(addr)) { return addr; } else { throw new UnknownHostException("Cannot find address of local host which can be used for multicasting"); } }
private static int joinMcGroupsOnAllNetworkInterfaces(MulticastSocket pSocket, InetSocketAddress pSocketAddress, LogHandler pLogHandler) throws IOException { // V6: ffx8::/16 Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); int interfacesJoined = 0; while (nifs.hasMoreElements()) { NetworkInterface n = nifs.nextElement(); if (NetworkUtil.isMulticastSupported(n)) { try { pSocket.joinGroup(pSocketAddress, n); interfacesJoined++; } catch (IOException exp) { pLogHandler.info("Cannot join multicast group on NIF " + n.getDisplayName() + ": " + exp.getMessage()); } } } return interfacesJoined; }
/** * Check whether the given address' interface supports multicast * * @param pAddr address to check * @return true if the underlying networkinterface is up and supports multicast * @throws SocketException */ public static boolean isMulticastSupported(InetAddress pAddr) throws SocketException { return isMulticastSupported(NetworkInterface.getByInetAddress(pAddr)); }
/** * Check whether the given address' interface supports multicast * * @param pAddr address to check * @return true if the underlying networkinterface is up and supports multicast * @throws SocketException */ public static boolean isMulticastSupported(InetAddress pAddr) throws SocketException { return isMulticastSupported(NetworkInterface.getByInetAddress(pAddr)); }
/** * Get a local address which supports multicast. A loopback adress is returned, but only if not * another is available * * @return a multicast enabled address of null if none could be found * @throws UnknownHostException * @throws SocketException */ public static InetAddress getLocalAddressWithMulticast() throws UnknownHostException, SocketException { InetAddress addr = InetAddress.getLocalHost(); NetworkInterface nif = NetworkInterface.getByInetAddress(addr); if (addr.isLoopbackAddress() || addr instanceof Inet6Address || !isMulticastSupported(nif)) { // Find local address that isn't a loopback address InetAddress lookedUpAddr = findLocalAddressViaNetworkInterface(); // If a local, multicast enabled address can be found, use it. Otherwise // we are using the local address, which might not be what you want if (lookedUpAddr != null) { return lookedUpAddr; } addr = InetAddress.getByName("127.0.0.1"); } if (isMulticastSupported(addr)) { return addr; } else { throw new UnknownHostException("Cannot find address of local host which can be used for multicasting"); } }
/** * Get a local address which supports multicast. A loopback adress is returned, but only if not * another is available * * @return a multicast enabled address of null if none could be found * @throws UnknownHostException * @throws SocketException */ public static InetAddress getLocalAddressWithMulticast() throws UnknownHostException, SocketException { InetAddress addr = InetAddress.getLocalHost(); NetworkInterface nif = NetworkInterface.getByInetAddress(addr); if (addr.isLoopbackAddress() || addr instanceof Inet6Address || !isMulticastSupported(nif)) { // Find local address that isn't a loopback address InetAddress lookedUpAddr = findLocalAddressViaNetworkInterface(); // If a local, multicast enabled address can be found, use it. Otherwise // we are using the local address, which might not be what you want if (lookedUpAddr != null) { return lookedUpAddr; } addr = InetAddress.getByName("127.0.0.1"); } if (isMulticastSupported(addr)) { return addr; } else { throw new UnknownHostException("Cannot find address of local host which can be used for multicasting"); } }
private static int joinMcGroupsOnAllNetworkInterfaces(MulticastSocket pSocket, InetSocketAddress pSocketAddress, LogHandler pLogHandler) throws IOException { // V6: ffx8::/16 Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); int interfacesJoined = 0; while (nifs.hasMoreElements()) { NetworkInterface n = nifs.nextElement(); if (NetworkUtil.isMulticastSupported(n)) { try { pSocket.joinGroup(pSocketAddress, n); interfacesJoined++; } catch (IOException exp) { pLogHandler.info("Cannot join multicast group on NIF " + n.getDisplayName() + ": " + exp.getMessage()); } } } return interfacesJoined; }
private static int joinMcGroupsOnAllNetworkInterfaces(MulticastSocket pSocket, InetSocketAddress pSocketAddress, LogHandler pLogHandler) throws IOException { // V6: ffx8::/16 Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); int interfacesJoined = 0; while (nifs.hasMoreElements()) { NetworkInterface n = nifs.nextElement(); if (NetworkUtil.isMulticastSupported(n)) { try { pSocket.joinGroup(pSocketAddress, n); interfacesJoined++; } catch (IOException exp) { pLogHandler.info("Cannot join multicast group on NIF " + n.getDisplayName() + ": " + exp.getMessage()); } } } return interfacesJoined; }