50,523
社区成员
发帖
与我相关
我的任务
分享
try {
ServerBootstrap bootstrap = new ServerBootstrap()
.group(boss, worker)
.channel(NioServerSocketChannel.class)
.localAddress(inetSocketAddress)
.childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new HvacChannelInitializer(context));
ChannelFuture future = bootstrap.bind().sync();
if (future.isSuccess()) {
log.info("[TCP Server] server started @ {}:{}", ip, tcpPort);
}
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
log.error("[TCP Server] server started failed", e);
} finally {
boss.shutdownGracefully();
worker.shutdownGracefully();
preDestroy();
}