Skip to content

Instantly share code, notes, and snippets.

@trustin
Created July 4, 2012 00:42
Show Gist options
  • Save trustin/3044400 to your computer and use it in GitHub Desktop.
Save trustin/3044400 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(new NioServerSocketChannel())
.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();
}
}
@recastrodiaz
Copy link

Line 6 should be ".channel(NioServerSocketChannel.class)" since 4.0.0.Alpha4.
Cf. https://netty.io/Blog/Netty+400Alpha4+is+out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment