简体   繁体   English

在Netty 4.0.15中,java.nio.channels.IllegalSelectorException异常

[英]In Netty 4.0.15, java.nio.channels.IllegalSelectorException exception

I am trying to create a server for receiving UDP messages using NioUdtMessageConnectorChannel as channel. 我正在尝试创建服务器,以使用NioUdtMessageConnectorChannel作为通道接收UDP消息。 Pasting the code for the server 粘贴服务器代码

EventLoopGroup group = new NioEventLoopGroup(50,
                Executors.defaultThreadFactory());


    try {
        Bootstrap b = new Bootstrap();
        b.group(group);
        b.channel(NioUdtMessageConnectorChannel.class);
        b.option(UdtChannelOption.SO_BROADCAST, true);
        b.option(UdtChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1024);
        b.option(UdtChannelOption.PROTOCOL_RECEIVE_BUFFER_SIZE, 1024);
        b.option(UdtChannelOption.PROTOCOL_SEND_BUFFER_SIZE, 1024);
        b.option(UdtChannelOption.TCP_NODELAY, true);
        b.option(UdtChannelOption.SO_RCVBUF, 256 * 1024);
        b.handler(new SNMPTrapHandler());
        b.bind(PORT).sync().channel().closeFuture().await();
    } finally {
        group.shutdownGracefully();
    }

However, I am getting below error 但是,我得到以下错误

log4j:WARN Please initialize the log4j system properly.
java.nio.channels.IllegalSelectorException
    at sun.nio.ch.SelectorImpl.register(Unknown Source)
    at java.nio.channels.spi.AbstractSelectableChannel.register(Unknown Source)
    at io.netty.channel.nio.AbstractNioChannel.doRegister(AbstractNioChannel.java:308)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:439)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.access$100(AbstractChannel.java:374)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:418)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.run(Unknown Source)

What is the exact error? 确切的错误是什么?

You have to specify the UDT selector provider when you create an NioEventLoopGroup . 创建NioEventLoopGroup时,必须指定UDT选择器提供程序。 For example: 例如:

new NioEventLoopGroup(..., NioUdtProvider.MESSAGE_PROVIDER);

For more information, please refer to the UDT examples . 有关更多信息,请参考UDT示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM