netty4一个进程内监听多个端口
使用netty框架,怎么在一个进程内监听多个端口
当监听一个端口后,监听会进入阻塞,那另一个端口就没法监听了。
示例程序如下
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(
//new LoggingHandler(LogLevel.INFO),
new EchoServerHandler());
}
});
// Start the server.
ChannelFuture f = b.bind(port).sync();
ChannelFuture fq = b.bind(9802).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync(); ->这里会进入阻塞下边的wait没法进行
fq .channel().closeFuture().sync();
求高手解答,分不多,谢谢