-
-
Save recastrodiaz/4106108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void main(String[] args) throws Exception { | |
| // Configure the server. | |
| ServerBootstrap b = new ServerBootstrap(); | |
| try { | |
| b.group(new NioEventLoopGroup(), new NioEventLoopGroup()) | |
| .channel(NioServerSocketChannel.class) | |
| .option(ChannelOption.SO_BACKLOG, 100) | |
| .localAddress(8080) | |
| .childOption(ChannelOption.TCP_NODELAY, true) | |
| .childHandler(new ChannelInitializer<SocketChannel>() { | |
| @Override | |
| public void initChannel(SocketChannel ch) throws Exception { | |
| ch.pipeline().addLast(handler1, handler2, ...); | |
| } | |
| }); | |
| // Start the server. | |
| ChannelFuture f = b.bind().sync(); | |
| // Wait until the server socket is closed. | |
| f.channel().closeFuture().sync(); | |
| } finally { | |
| // Shut down all event loops to terminate all threads. | |
| b.shutdown(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment