WaliedYassen
WaliedYassen

Reputation: 65

Netty 5 after bind issue

Okay so here's my problem:

I'm building a netty 5 server in purpose of learning, but i came across this problem, Which is after binding problem:

So when i bind an port in netty 5 i do as this code:

bind(port).channel().closeFuture().sync();

Now the code that come after that line won't execute, code such as:
System.out.println("Server bound!");

How do i make it execute that code after binding?

Upvotes: 0

Views: 98

Answers (1)

ARau
ARau

Reputation: 489

The sync() call to the future object is a blocking call meaning it will wait for the socket to terminate. If you want some code to run after the bind then you will need to do something like:

ChannelFuture future = bind(port).channel().closeFuture();

System.out.println("Bound to port!");

future.sync(); // this will block until the port is shut down

Upvotes: 3

Related Questions