Created
November 15, 2012 06:08
-
-
Save danbev/4076911 to your computer and use it in GitHub Desktop.
WebSocketEnhancmentNettyBoot
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 { | |
final ServerBootstrap sb = new ServerBootstrap(); | |
try { | |
sb.group(new NioEventLoopGroup(), new NioEventLoopGroup()) | |
.channel(NioServerSocketChannel.class) | |
.localAddress(new InetSocketAddress(port)) | |
.childHandler(new ChannelInitializer<SocketChannel>() { | |
@Override | |
public void initChannel(final SocketChannel ch) throws Exception { | |
ch.pipeline().addLast( | |
new HttpRequestDecoder(), | |
new HttpChunkAggregator(65536), | |
new HttpResponseEncoder(), | |
new WebSocketServerProtocolHandler("/websocket"), | |
new CustomTextFrameHandler()); | |
} | |
}); | |
final Channel ch = sb.bind().sync().channel(); | |
System.out.println("Web socket server started at port " + port); | |
ch.closeFuture().sync(); | |
} finally { | |
sb.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment