BasicMulticastSocketHandler.java 文件源码

java
阅读 17 收藏 0 点赞 0 评论 0

项目:wot_gateways 作者:
public BasicMulticastSocketHandler(ChannelManager channelManager,
        int port, InetAddress multicastIP) throws IOException {
    logger.addAppender(new ConsoleAppender(new SimpleLayout()));
    // ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF:
    logger.setLevel(Level.WARN);

    NetworkInterface interf = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
    //NetworkInterface interf = NetworkInterface.getByName("eth0");

    this.channelManager = channelManager;
    mcastChannel = DatagramChannel.open(StandardProtocolFamily.INET);
    mcastChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
    mcastChannel.bind(new InetSocketAddress(port));     
    mcastChannel.setOption(StandardSocketOptions.IP_MULTICAST_IF, interf);
    mcastChannel.join(multicastIP, interf);
    mcastChannel.configureBlocking(false);

    this.localPort = mcastChannel.socket().getLocalPort();
    this.localAddr = multicastIP;

    workerThread = new WorkerThread();
    workerThread.start();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号