我正在尝试使用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)
确切错误是什么?
答案 0 :(得分:1)
创建NioEventLoopGroup
时必须指定UDT选择器提供程序。例如:
new NioEventLoopGroup(..., NioUdtProvider.MESSAGE_PROVIDER);
有关详细信息,请参阅the UDT examples。