我有一个问题。
什么时间必须使用.option(),什么时间必须使用.childOption()?
我有服务器。
我在下面的行中设置服务器。是正确的吗?
.option(ChannelOption.SO_BACKLOG, defaultConnectionBacklog);
.option(ChannelOption.SO_REUSEADDR, true);
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
.childOption(ChannelOption.SO_KEEPALIVE, true);
.childOption(ChannelOption.SO_REUSEADDR, true);
.childOption(ChannelOption.TCP_NODELAY, true);
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
启动服务器时:
[option
由XXXServerSocketChannel使用(例如NioServerSocketChannel
)
[childOption
由此ServerChannel所支持的通道使用
启动客户时:
您只能使用option
,因为没有子频道存在。
所以在您的问题中,.childOption(ChannelOption.SO_REUSEADDR, true);
在接受的频道中无用
[更多详细信息,您可以阅读channelRead
类中的方法ServerBootstrapAcceptor
,该代码是ServerChannel接受频道时要执行的操作。
P.S。 ServerBootstrapAcceptor
是ServerChannel管道中的默认处理程序。