我想在一个Netty应用程序中绑定两个服务器套接字(例如端口8000、8001)。
我尝试合并DiscardServer和EchoServer示例进行测试。
但是在第一个服务器初始化代码中,
ChannelFuture f = bootstrap1.bind(port).sync();
f.channel().closeFuture().sync(); // <-- program blocks here
程序执行被阻止,因此第二个服务器初始化代码无法到达。
如何使用Netty 4.0启动两个不同的端口服务器?
只需评论该条款
f.channel().closeFuture().sync(); // <-- program blocks here
谢谢大家!有效。只为别人,我不得不补充f.channel()。closeFuture()。sync();在第二个bind()之后;
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new HttpServerInitializer(sslContext));
b.bind(4443).sync();
ServerBootstrap b1 = new ServerBootstrap();
b1.group(bossGroupNonSSL, workerGroupNonSSL)
.channel(NioServerSocketChannel.class)
.childHandler(new HttpServerNonSSL());
ChannelFuture f = b1.bind(4080).sync();
f.channel().closeFuture().sync();