netty绑定端口报错bug解决

This commit is contained in:
guoshengxiong 2025-04-07 17:05:32 +08:00
parent 37539074a4
commit cb45d95486

View File

@ -53,17 +53,21 @@ public class NettyTcpServer {
*/
@PostConstruct
public void start() throws InterruptedException {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(jt808ChannelInitializer)
.option(ChannelOption.SO_BACKLOG, 1024) //服务端可连接队列数,对应TCP/IP协议listen函数中backlog参数
.childOption(ChannelOption.TCP_NODELAY, true)//立即写出
.childOption(ChannelOption.SO_KEEPALIVE, true);//长连接
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.SIMPLE);//内存泄漏检测 开发推荐PARANOID 线上SIMPLE
ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
if (channelFuture.isSuccess()) {
log.info("定位TCP服务启动完毕,port={}", this.port);
try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(jt808ChannelInitializer)
.option(ChannelOption.SO_BACKLOG, 1024) //服务端可连接队列数,对应TCP/IP协议listen函数中backlog参数
.childOption(ChannelOption.TCP_NODELAY, true)//立即写出
.childOption(ChannelOption.SO_KEEPALIVE, true);//长连接
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.SIMPLE);//内存泄漏检测 开发推荐PARANOID 线上SIMPLE
ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
if (channelFuture.isSuccess()) {
log.info("定位TCP服务启动完毕,port={}", this.port);
}
} catch (Exception e) {
log.error("定位TCP服务启动异常,port={}", this.port);
}
}