Skip to content

Instantly share code, notes, and snippets.

@codingtony
Created September 24, 2013 21:10
Show Gist options
  • Save codingtony/6691297 to your computer and use it in GitHub Desktop.
Save codingtony/6691297 to your computer and use it in GitHub Desktop.
Example to add a ChannelFutureListener to trap the BindException in Netty
//...
final int port=8888;
ServerBootstrap b = new ServerBootstrap();
//...
b.bind(port).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (!future.isSuccess()) {
if (future.cause() instanceof BindException) {
System.err.println("Bind Exception on port : " + port);
}
}
}
}).sync().channel().closeFuture().sync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment