diff --git a/src/main/java/org/spacehq/packetlib/tcp/TcpConnectionListener.java b/src/main/java/org/spacehq/packetlib/tcp/TcpConnectionListener.java index f8c1bb41..c9e363a9 100644 --- a/src/main/java/org/spacehq/packetlib/tcp/TcpConnectionListener.java +++ b/src/main/java/org/spacehq/packetlib/tcp/TcpConnectionListener.java @@ -87,24 +87,29 @@ public class TcpConnectionListener implements ConnectionListener { server.addSession(session); } - }).group(this.group).localAddress(this.host, this.port).bind().addListener(new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture channelFuture) throws Exception { - if(channelFuture.isSuccess()) { - channel = channelFuture.channel(); - callback.run(); - } else if(channelFuture.cause() != null && !wait) { - System.err.println("[ERROR] Failed to asynchronously bind connection listener."); - channelFuture.cause().printStackTrace(); - } - } - }); + }).group(this.group).localAddress(this.host, this.port).bind(); if(wait) { try { future.sync(); } catch(InterruptedException e) { } + + channel = future.channel(); + callback.run(); + } else { + future.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + if(channelFuture.isSuccess()) { + channel = channelFuture.channel(); + callback.run(); + } else if(channelFuture.cause() != null && !wait) { + System.err.println("[ERROR] Failed to asynchronously bind connection listener."); + channelFuture.cause().printStackTrace(); + } + } + }); } }