content: package Test;
  
  import io.netty.bootstrap.ServerBootstrap;
  import io.netty.channel.ChannelFuture;
  import io.netty.channel.ChannelInitializer;
  import io.netty.channel.EventLoopGroup;
  import io.netty.channel.nio.NioEventLoopGroup;
  import io.netty.channel.socket.SocketChannel;
  import io.netty.channel.socket.nio.NioServerSocketChannel;
  
  /**
   * Created by hzcortex on 17-1-29.
   */
  public class ChatServer {
      private int port;
  
      public ChatServer(int port) {
          this.port = port;
      }
  
      public void run() throws Exception {
          EventLoopGroup bossGroup = new NioEventLoopGroup();
          EventLoopGroup workerGroup = new NioEventLoopGroup();
          try {
              ServerBootstrap bootstrap = new ServerBootstrap();
              bootstrap.group(bossGroup, workerGroup)
                      .channel(NioServerSocketChannel.class)
  //                    .childHandler(new ChannelInitializer<SocketChannel>() {
  //                        @Override
  //                        public void initChannel(SocketChannel ch) {
  //                            ch.pipeline().addLast(new ChatServerHandler());
  //                        }
  //                    });
                      .childHandler(new ChatServerInitializer());
              ChannelFuture future = bootstrap.bind(port).sync();
  
              future.channel().closeFuture().sync();
          } finally {
              workerGroup.shutdownGracefully();
              bossGroup.shutdownGracefully();
          }
      }
  
      public static void main(String[] args) throws Exception {
          int port = 8000;
          new ChatServer(port).run();
      }
  }
  
  