本文整理汇总了Java中java.net.MulticastSocket.getNetworkInterface方法的典型用法代码示例。如果您正苦于以下问题:Java MulticastSocket.getNetworkInterface方法的具体用法?Java MulticastSocket.getNetworkInterface怎么用?Java MulticastSocket.getNetworkInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.MulticastSocket
的用法示例。
在下文中一共展示了MulticastSocket.getNetworkInterface方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFrame
import java.net.MulticastSocket; //导入方法依赖的package包/类
public void sendFrame(final Frame frame) throws IOException {
final byte[] message = toValidMessage(frame);
final DatagramPacket packet = new DatagramPacket(message, 0, message.length, mcastAddress, mcastPort);
for (final MulticastSocket mcastSocket : mcastSockets) {
try {
sentMessages++;
mcastSocket.send(packet);
} catch (final IOException e) {
final String exceptionMessage = e.getMessage();
if (exceptionMessage.endsWith(NO_BUFFER_SPACE_AVAILABLE)
|| exceptionMessage.endsWith(NO_ROUTE_TO_HOST)) {
final NetworkInterface networkInterface = mcastSocket.getNetworkInterface();
final InetAddress mcastSocketInterface = mcastSocket.getInterface();
LOG.warn(createIgnoredWarning(exceptionMessage, networkInterface, mcastSocketInterface));
} else {
throw e;
}
}
}
}
示例2: main
import java.net.MulticastSocket; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
boolean passed = true;
try {
MulticastSocket ms = new MulticastSocket();
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface netIf = networkInterfaces.nextElement();
if (isNetworkInterfaceTestable(netIf)) {
printNetIfDetails(netIf);
ms.setNetworkInterface(netIf);
NetworkInterface msNetIf = ms.getNetworkInterface();
if (netIf.equals(msNetIf)) {
System.out.println(" OK");
} else {
System.out.println("FAILED!!!");
printNetIfDetails(msNetIf);
passed = false;
}
System.out.println("------------------");
}
}
} catch (IOException e) {
e.printStackTrace();
passed = false;
}
if (!passed) {
throw new RuntimeException("Test Fail");
}
System.out.println("Test passed ");
}