Netty设置option警告Unknown channel option

本文使用环境版本是
netty 4.1.36.Final
jdk 1.8

经查,问题的关键点事childOption和option的问题,找了几个答案如下:

option主要是设置的ServerChannel的一些选项,而childOption主要是设置的ServerChannel的子Channel的选项。 如果是Bootstrap的话,只会有option而没有childOption,所以设置的是客户端Channel的选项。

option主要是针对boss线程组,child主要是针对worker线程组

The parameters that we set using ServerBootStrap.option apply to the ChannelConfig of a newly created ServerChannel, i.e., the server socket which listens for and accepts the client connections.
These options will be set on the Server Channel when bind() or connect() method is called. This channel is one per server.
And the ServerBootStrap.childOption applies to to a channel’s channelConfig which gets created once the serverChannel accepts a client connection.
This channel is per client (or per client socket).
So ServerBootStrap.option parameters apply to the server socket (Server channel) that is listening for connections and ServerBootStrap.
childOption parameters apply to the socket that gets created once the connection is accepted by the server socket.
The same can be extended to attr vs childAttr and handler vs childHandler methods in the ServerBootstrap class.
How could I know which option should be an option and which should be a childOption ?Which ChannelOptions are supported depends on the channel type we are using.
You can refer to the API docs for the ChannelConfig that you’re using.
netty.io/4.0/api/io/netty/channel/ChannelConfig.html
and its sub classes. You should find Available Options section for each ChannelConfig.

在设置netty服务端的option时,设置了如下参数。

server.group(boss,worker)//设置时间循环对象,前者用来处理accept事件,后者用于处理已经建立的连接的io
                //Server是NioServerSocketChannel 客户端是NioSocketChannel绑定了jdk NIO创建的ServerSocketChannel对象,
                //用它来建立新accept的连接
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG,1024)//
                // 第2次握手服务端向客户端发送请求确认,同时把此连接放入队列A中,
                // 然后客户端接受到服务端返回的请求后,再次向服务端发送请求,表示准备完毕,此时服务端收到请求,把这个连接从队列A移动到队列B中,
                // 此时A+B的总数,不能超过SO_BACKLOG的数值,满了之后无法建立新的TCP连接,2次握手后和3次握手后的总数
                // 当服务端从队列B中按照FIFO的原则获取到连接并且建立连接[ServerSocket.accept()]后,B中对应的连接会被移除,这样A+B的数值就会变小
                //此参数对于程序的连接数没影响,会影响正在准备建立连接的握手。
                .option(ChannelOption.SO_KEEPALIVE,true)
                //启用心跳,双方TCP套接字建立连接后(即都进入ESTABLISHED状态),
                // 并且在两个小时左右上层没有任何数据传输的情况下,这套机制才会被激活,TCP会自动发送一个活动探测数据报文
                .option(ChannelOption.TCP_NODELAY,true)
                //TCP协议中,TCP总是希望每次发送的数据足够大,避免网络中充满了小数据块。
                // Nagle算法就是为了尽可能的发送大数据快。
                // TCP_NODELAY就是控制是否启用Nagle算法。
                // 如果要求高实时性&#x
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值