服务器在bind方法中完成初始化,核心方法为doBind方法,该方法主要完成
- 执行initAndRegister方法
- 执行doBind方法
initAndRegister
- 使用channelFactory.newChannel()方法反射创建一个NIOServerSocketChannel对象,同时创建了一个NioServerSocketChannelConfig对象。
- 对NioServerSocketChannelConfig调用init方法完成初始化
2.1 init方法- 设置NioServerSocketChannel的TCP属性
- 通过ServerBootstrap的bossGroup注册NioServerSocketChannel
- 获取返回的Future
doBind
- Netty的doBind方法最终执行到Nio的doBind方法
- 绑定完成后使用for循环,循环判断监听事件