我正在尝试创建服务器,以使用NioUdtMessageConnectorChannel作为通道接收UDP消息。粘贴服务器代码

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();
    }


但是,我得到以下错误

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)


确切的错误是什么?

最佳答案

创建NioEventLoopGroup时必须指定UDT选择器提供程序。例如:

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


有关更多信息,请参阅the UDT examples

关于java - 在Netty 4.0.15中,java.nio.channels.IllegalSelectorException异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21309836/

10-10 16:10