// Bind and start to accept incoming connections. // 服务端启动核心逻辑,初始化Channel并绑定指定服务端口开始监听 ChannelFuture f = b.bind(port).sync();
// Wait until the server socket is closed. // In this example, this does not happen, but you can do that to gracefully // shut down your server. f.channel().closeFuture().sync(); } finally { // 服务端关闭 workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); } }
publicstaticvoidmain(String[] args)throws Exception { int port = 8080; if (args.length > 0) { port = Integer.parseInt(args[0]); }