content: package com.lgp.netty.netty_ch6;
  
  import io.netty.channel.Channel;
  import io.netty.channel.ChannelInitializer;
  import io.netty.channel.ChannelPipeline;
  import io.netty.channel.group.ChannelGroup;
  import io.netty.handler.codec.http.HttpObjectAggregator;
  import io.netty.handler.codec.http.HttpServerCodec;
  import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
  import io.netty.handler.stream.ChunkedWriteHandler;
  
  /**
   * @AUTHOR lgp
   * @DATE 2019/1/2 17:16
   * @DESCRIPTION  扩展 ChannelInitializer
   **/
  public class ChatServerInitializer extends ChannelInitializer<Channel> {
      private final ChannelGroup group;
  
      public ChatServerInitializer(ChannelGroup group) {
          this.group = group;
      }
  
      @Override
      protected void initChannel(Channel ch) throws Exception {            //2 添加 ChannelHandler　到 ChannelPipeline
          ChannelPipeline pipeline = ch.pipeline();
          pipeline.addLast(new HttpServerCodec());
          pipeline.addLast(new HttpObjectAggregator(64 * 1024));
          pipeline.addLast(new ChunkedWriteHandler());
          pipeline.addLast(new HttpRequestHandler("/ws"));
          pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
          pipeline.addLast(new TextWebSocketFrameHandler(group));
      }
  }
  