netty通信流程

nio通信流程

1 打开ServerSocketChannel通道 并绑定端口

2 启用多路复用器 Selector

3 将 ServerSocketChannel 注册到 复用器 Selector上,监听通道中的事件

4 在线程run中 轮询取出通道中就绪的事件 keys

ServerBootstrap init

  @Override
    void init(Channel channel) throws Exception {
        final Map<ChannelOption<?>, Object> options = options0();
        synchronized (options) {
            setChannelOptions(channel, options, logger);
        }

        final Map<AttributeKey<?>, Object> attrs = attrs0();
        synchronized (attrs) {
            for (Entry<AttributeKey<?>, Object> e: attrs.entrySet()) {
                @SuppressWarnings("unchecked")
                AttributeKey<Object> key = (AttributeKey<Object>) e.getKey();
                channel.attr(key).set(e.getValue());
            }
        }

        ChannelPipeline p = channel.pipeline();

        final EventLoopGroup cu

版权声明:本文为kao123yaojinqian原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。