Skip to content

Instantly share code, notes, and snippets.

@recastrodiaz
Forked from trustin/gist:3044400
Created November 18, 2012 16:32
Show Gist options
  • Select an option

  • Save recastrodiaz/4106108 to your computer and use it in GitHub Desktop.

Select an option

Save recastrodiaz/4106108 to your computer and use it in GitHub Desktop.
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