当前位置: 首页>>代码示例>>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;未经允许,请勿转载。