本文整理汇总了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();
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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));
}