简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM