當前位置: 首頁>>代碼示例>>Java>>正文


Java NetworkInterface.supportsMulticast方法代碼示例

本文整理匯總了Java中java.net.NetworkInterface.supportsMulticast方法的典型用法代碼示例。如果您正苦於以下問題:Java NetworkInterface.supportsMulticast方法的具體用法?Java NetworkInterface.supportsMulticast怎麽用?Java NetworkInterface.supportsMulticast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.NetworkInterface的用法示例。


在下文中一共展示了NetworkInterface.supportsMulticast方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: formatFlags

import java.net.NetworkInterface; //導入方法依賴的package包/類
/** format network interface flags */
private static String formatFlags(NetworkInterface nic) throws SocketException {
    StringBuilder flags = new StringBuilder();
    if (nic.isUp()) {
        flags.append("UP ");
    }
    if (nic.supportsMulticast()) {
        flags.append("MULTICAST ");
    }
    if (nic.isLoopback()) {
        flags.append("LOOPBACK ");
    }
    if (nic.isPointToPoint()) {
        flags.append("POINTOPOINT ");
    }
    if (nic.isVirtual()) {
        flags.append("VIRTUAL ");
    }
    flags.append("mtu:" + nic.getMTU());
    flags.append(" index:" + nic.getIndex());
    return flags.toString();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:IfConfig.java

示例2: selectMulticastInterface

import java.net.NetworkInterface; //導入方法依賴的package包/類
NetworkInterface selectMulticastInterface(InetSocketAddress node) throws HekateException {
    InetAddress address = node.getAddress();

    try {
        if (DEBUG) {
            log.debug("Resolving a network interface [address={}]", address);
        }

        NetworkInterface nif = NetworkInterface.getByInetAddress(address);

        if (nif == null && address.isLoopbackAddress()) {
            if (DEBUG) {
                log.debug("Failed to resolve a network interface for a loopback address. Will try to find a loopback interface.");
            }

            nif = findLoopbackInterface(address);
        }

        if (nif == null) {
            throw new HekateException("Failed to resolve a network interface by address [address=" + address + ']');
        }

        if (!nif.supportsMulticast()) {
            throw new HekateException("Network interface doesn't support multicasting [name=" + nif.getName()
                + ", interface-address=" + address + ']');
        }

        return nif;
    } catch (IOException e) {
        throw new HekateException("Failed to resolve multicast network interface [interface-address=" + address + ']', e);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:33,代碼來源:MulticastSeedNodeProvider.java

示例3: selectLocalAddress

import java.net.NetworkInterface; //導入方法依賴的package包/類
private InetAddress selectLocalAddress() throws Exception {
    InetAddress cached = LOCAL_ADDRESS_CACHE.get();

    if (cached == null) {
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();

        for (NetworkInterface nif : Iterables.toIterable(interfaces)) {
            if (nif.isUp() && !nif.isLoopback() && nif.supportsMulticast()) {
                for (InetAddress addr : Iterables.toIterable(nif.getInetAddresses())) {
                    if (!addr.isLinkLocalAddress()) {
                        cached = addr;

                        break;
                    }
                }

                if (cached != null) {
                    break;
                }
            }
        }

        if (cached == null) {
            cached = InetAddress.getLocalHost();
        }

        LOCAL_ADDRESS_CACHE.set(cached);
    }

    return cached;
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:32,代碼來源:HekateTestBase.java

示例4: JdpBroadcaster

import java.net.NetworkInterface; //導入方法依賴的package包/類
/**
 * Create a new broadcaster
 *
 * @param address - multicast group address
 * @param srcAddress - address of interface we should use to broadcast.
 * @param port - udp port to use
 * @param ttl - packet ttl
 * @throws IOException
 */
public JdpBroadcaster(InetAddress address, InetAddress srcAddress, int port, int ttl)
        throws IOException, JdpException {
    this.addr = address;
    this.port = port;

    ProtocolFamily family = (address instanceof Inet6Address)
            ? StandardProtocolFamily.INET6 : StandardProtocolFamily.INET;

    channel = DatagramChannel.open(family);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    channel.setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl);

    // with srcAddress equal to null, this constructor do exactly the same as
    // if srcAddress is not passed
    if (srcAddress != null) {
        // User requests particular interface to bind to
        NetworkInterface interf = NetworkInterface.getByInetAddress(srcAddress);

        if (interf == null) {
            throw new JdpException("Unable to get network interface for " + srcAddress.toString());
        }

        if (!interf.isUp()) {
            throw new JdpException(interf.getName() + " is not up.");
        }

        if (!interf.supportsMulticast()) {
            throw new JdpException(interf.getName() + " does not support multicast.");
        }

        try {
            channel.bind(new InetSocketAddress(srcAddress, 0));
        } catch (UnsupportedAddressTypeException ex) {
            throw new JdpException("Unable to bind to source address");
        }
        channel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:48,代碼來源:JdpBroadcaster.java

示例5: isNetworkInterfaceTestable

import java.net.NetworkInterface; //導入方法依賴的package包/類
private static boolean isNetworkInterfaceTestable(NetworkInterface netIf) throws Exception {
    System.out.println("checking netif == " + netIf.getName());
    return  (netIf.isUp() && netIf.supportsMulticast() && isIpAddrAvailable(netIf));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:SetGetNetworkInterfaceTest.java


注:本文中的java.net.NetworkInterface.supportsMulticast方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。