• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java OioDatagramChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.channel.socket.oio.OioDatagramChannel的典型用法代码示例。如果您正苦于以下问题:Java OioDatagramChannel类的具体用法?Java OioDatagramChannel怎么用?Java OioDatagramChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OioDatagramChannel类属于io.netty.channel.socket.oio包,在下文中一共展示了OioDatagramChannel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: init

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
public void init(ChannelPipelineFactory factory) throws Exception
{
	id = String.format("%1$020d",
			Math.abs(new Random(System.currentTimeMillis()).nextLong()))
			.getBytes();

	group = new OioEventLoopGroup();
	connectionlessBootstrap = new Bootstrap();
	connectionlessBootstrap.group(group);
	connectionlessBootstrap.option(ChannelOption.SO_BROADCAST, true);
	connectionlessBootstrap.handler(factory);
	connectionlessBootstrap.channel(OioDatagramChannel.class);
	;
	datagramChannel = (DatagramChannel) connectionlessBootstrap
			.bind(new InetSocketAddress(mcastGroupPort)).sync().channel();
	multicastAddress = new InetSocketAddress(mcastGroupIp, mcastGroupPort);
	NetworkInterface networkInterface = NetworkInterface
			.getByInetAddress(InetAddress.getByName(bindAddress));
	// for (Enumeration nifs = NetworkInterface.getNetworkInterfaces();
	// nifs.hasMoreElements(); )
	datagramChannel.joinGroup(multicastAddress, null);// (NetworkInterface)
														// nifs.nextElement());
	init = true;
	if (debug)
		factory.debug();
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:27,代码来源:MulticastEndpoint.java


示例2: createUDPBootstrap

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
public static Bootstrap createUDPBootstrap(final ChannelType channelType) throws UnsupportedOperationException {
    Bootstrap bootstrap = new Bootstrap();

    switch (channelType) {
        case NIO:
        	
            bootstrap.group(new NioEventLoopGroup());
            bootstrap.channel(NioDatagramChannel.class);
            return bootstrap;

        case OIO:
        	
            bootstrap.group(new OioEventLoopGroup());
            bootstrap.channel(OioDatagramChannel.class);
            return bootstrap;

        default:
            throw new UnsupportedOperationException("Failed to create Bootstrap,  " + channelType + " not supported!");
    }
}
 
开发者ID:desperado1992,项目名称:distributeTemplate,代码行数:21,代码来源:BootstrapFactory.java


示例3: createServerBootstrap

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
public static Bootstrap createServerBootstrap(final ChannelType channelType) throws UnsupportedOperationException {
    
	Bootstrap serverBootstrap = new Bootstrap();

    switch (channelType) {
        case NIO:
            serverBootstrap.group(new NioEventLoopGroup(Runtime.getRuntime().availableProcessors()));
            serverBootstrap.channel(NioDatagramChannel.class);
           // serverBootstrap.localAddress(new InetSocketAddress(port))
           // .handler(packetHandler);
          
            return serverBootstrap;

        case OIO:
        	 serverBootstrap.group(new OioEventLoopGroup(Runtime.getRuntime().availableProcessors()));
             serverBootstrap.channel(OioDatagramChannel.class);
          
            
            return serverBootstrap;

        default:
            throw new UnsupportedOperationException("Failed to create ServerBootstrap,  " + channelType + " not supported!");
    }
}
 
开发者ID:desperado1992,项目名称:distributeTemplate,代码行数:25,代码来源:ServerUDPBootstrapFactory.java


示例4: datagram

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
public List<BootstrapComboFactory<Bootstrap, Bootstrap>> datagram() {
    // Make the list of Bootstrap factories.
    List<BootstrapFactory<Bootstrap>> bfs = Arrays.asList(
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                        @Override
                        public Channel newChannel() {
                            return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                        }

                        @Override
                        public String toString() {
                            return NioDatagramChannel.class.getSimpleName() + ".class";
                        }
                    });
                }
            },
            new BootstrapFactory<Bootstrap>() {
                @Override
                public Bootstrap newInstance() {
                    return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
                }
            }
    );

    // Populare the combinations.
    return combo(bfs, bfs);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:31,代码来源:SocketTestPermutation.java


示例5: testMulticast

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
    MulticastTestHandler mhandler = new MulticastTestHandler();

    sb.handler(new SimpleChannelInboundHandler<Object>() {
        @Override
        public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
            // Nothing will be sent.
        }
    });

    cb.handler(mhandler);

    sb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF);
    sb.option(ChannelOption.SO_REUSEADDR, true);
    cb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF);
    cb.option(ChannelOption.SO_REUSEADDR, true);
    cb.localAddress(addr.getPort());

    Channel sc = sb.bind().sync().channel();
    if (sc instanceof OioDatagramChannel) {
        // skip the test for OIO, as it fails because of
        // No route to host which makes no sense.
        // Maybe a JDK bug ?
        sc.close().awaitUninterruptibly();
        return;
    }
    DatagramChannel cc = (DatagramChannel) cb.bind().sync().channel();

    String group = "230.0.0.1";
    InetSocketAddress groupAddress = new InetSocketAddress(group, addr.getPort());

    cc.joinGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();

    sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
    assertTrue(mhandler.await());

    // leave the group
    cc.leaveGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();

    // sleep a second to make sure we left the group
    Thread.sleep(1000);

    // we should not receive a message anymore as we left the group before
    sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
    mhandler.await();

    sc.close().awaitUninterruptibly();
    cc.close().awaitUninterruptibly();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:50,代码来源:DatagramMulticastTest.java


示例6: datagram

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
    List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
            new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();

    // Make the list of Bootstrap factories.
    List<Factory<Bootstrap>> bfs =
            new ArrayList<Factory<Bootstrap>>();
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel() {
                   return new NioDatagramChannel(InternetProtocolFamily.IPv4);
                }

                @Override
                public String toString() {
                    return NioDatagramChannel.class.getSimpleName() + ".class";
                }
            });
        }
    });
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
        }
    });

    // Populate the combinations
    for (Factory<Bootstrap> sbf: bfs) {
        for (Factory<Bootstrap> cbf: bfs) {
            final Factory<Bootstrap> sbf0 = sbf;
            final Factory<Bootstrap> cbf0 = cbf;
            list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
                @Override
                public Factory<Bootstrap> getKey() {
                    return sbf0;
                }

                @Override
                public Factory<Bootstrap> getValue() {
                    return cbf0;
                }

                @Override
                public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    }

    return list;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:57,代码来源:SocketTestPermutation.java


示例7: datagram

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
    List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
            new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();

    // Make the list of Bootstrap factories.
    List<Factory<Bootstrap>> bfs = new ArrayList<Factory<Bootstrap>>();
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel(EventLoop eventLoop) {
                   return new NioDatagramChannel(eventLoop, InternetProtocolFamily.IPv4);
                }

                @Override
                public String toString() {
                    return NioDatagramChannel.class.getSimpleName() + ".class";
                }
            });
        }
    });
    bfs.add(new Factory<Bootstrap>() {
        @Override
        public Bootstrap newInstance() {
            return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
        }
    });

    // Populate the combinations
    for (Factory<Bootstrap> sbf: bfs) {
        for (Factory<Bootstrap> cbf: bfs) {
            final Factory<Bootstrap> sbf0 = sbf;
            final Factory<Bootstrap> cbf0 = cbf;
            list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
                @Override
                public Factory<Bootstrap> getKey() {
                    return sbf0;
                }

                @Override
                public Factory<Bootstrap> getValue() {
                    return cbf0;
                }

                @Override
                public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
                    throw new UnsupportedOperationException();
                }
            });
        }
    }

    return list;
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:56,代码来源:SocketTestPermutation.java


示例8: testMulticast

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
    MulticastTestHandler mhandler = new MulticastTestHandler();

    sb.handler(new SimpleChannelInboundHandler<Object>() {
        @Override
        public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
            // Nothing will be sent.
        }
    });

    cb.handler(mhandler);

    sb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF);
    sb.option(ChannelOption.SO_REUSEADDR, true);
    cb.option(ChannelOption.IP_MULTICAST_IF, NetUtil.LOOPBACK_IF);
    cb.option(ChannelOption.SO_REUSEADDR, true);
    cb.localAddress(addr.getPort());

    Channel sc = sb.bind().sync().channel();
    if (sc instanceof OioDatagramChannel) {
        // skip the test for OIO, as it fails because of
        // No route to host which makes no sense.
        // Maybe a JDK bug ?
        sc.close().awaitUninterruptibly();
        return;
    }
    DatagramChannel cc = (DatagramChannel) cb.bind().sync().channel();

    String group = "230.0.0.1";
    InetSocketAddress groupAddress = new InetSocketAddress(group, addr.getPort());

    cc.joinGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();

    sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
    assertTrue(mhandler.await());

    // leave the group
    cc.leaveGroup(groupAddress, NetUtil.LOOPBACK_IF).sync();

    // sleep a second to make sure we left the group
    Thread.sleep(1000);

    // we should not receive a message anymore as we left the group before
    sc.writeAndFlush(new DatagramPacket(Unpooled.copyInt(1), groupAddress)).sync();
    mhandler.await();

    sc.close().awaitUninterruptibly();
    cc.close().awaitUninterruptibly();
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:50,代码来源:DatagramMulticastTest.java


示例9: getChannelClass

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
@Override
protected Class<? extends Channel> getChannelClass() {
	return OioDatagramChannel.class;
}
 
开发者ID:flozano,项目名称:statsd-netty,代码行数:5,代码来源:NettyUDPServer.java


示例10: newChannel

import io.netty.channel.socket.oio.OioDatagramChannel; //导入依赖的package包/类
@Override
public OioDatagramChannel newChannel() {
	return new OioDatagramChannel();
}
 
开发者ID:DesignAndDeploy,项目名称:dnd,代码行数:5,代码来源:TCPUDPServerManager.java



注:本文中的io.netty.channel.socket.oio.OioDatagramChannel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PRNGFixes类代码示例发布时间:2022-05-22
下一篇:
Java AdHocCommandNote类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap