public NettyServer() {
mainGroup = new NioEventLoopGroup();
subGroup = new NioEventLoopGroup();
server = new ServerBootstrap();
server.group(mainGroup, subGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new NettyChannelInitializer());
}
public void start(int port) {
this.future = server.bind(port); log.info("netty server start success");
}
}管道初始化public class NettyChannelInitializer extends ChannelInitializer<SocketChannel>{
private static final Logger log = LoggerFactory.getLogger(NettyChannelInitializer.class);