当前位置: 首页>>代码示例>>Java>>正文


Java MulticastSocket.getNetworkInterface方法代码示例

本文整理汇总了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;
            }
         }
      }
   }
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:PlainMulticastSender.java

示例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 ");
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:SetGetNetworkInterfaceTest.java


注:本文中的java.net.MulticastSocket.getNetworkInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。