Created
July 4, 2012 00:42
-
-
Save trustin/3044400 to your computer and use it in GitHub Desktop.
This file contains 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(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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 6 should be ".channel(NioServerSocketChannel.class)" since 4.0.0.Alpha4.
Cf. https://netty.io/Blog/Netty+400Alpha4+is+out