From 4dd35c2051ec8ab7d12a9d9a521adf8da096e550 Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Tue, 27 Aug 2024 17:03:53 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E7=94=B5=E5=8D=95=E8=BD=A6=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricBicyclesServerHandler.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/electricbicycles/ElectricBicyclesServerHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/electricbicycles/ElectricBicyclesServerHandler.java index 4f97f467b..d8f1e65d5 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/electricbicycles/ElectricBicyclesServerHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/electricbicycles/ElectricBicyclesServerHandler.java @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.IOException; import java.net.InetSocketAddress; import java.util.List; import java.util.Map; @@ -123,13 +124,20 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter String channelIdShortText = channelId.asShortText(); String pileSn = PileChannelEntity.getPileSnByChannelId(channelIdShortText); log.error("发生异常 channelId:{}, pileSn:{}", channelIdShortText, pileSn, cause); - cause.printStackTrace(); + // cause.printStackTrace(); // 如果桩连到平台,在1分钟内没有发送数据过来,会报ReadTimeoutException异常 if (cause instanceof ReadTimeoutException) { - if (log.isTraceEnabled()) { - log.trace("Connection timeout 【{}】", ctx.channel().remoteAddress()); - } - log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, ChannelManagerUtil.getChannelCount()); + // if (log.isTraceEnabled()) { + // log.trace("Connection timeout 【{}】", ctx.channel().remoteAddress()); + // } + log.error("【{}】发生了错误: 读取超时, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, ChannelManagerUtil.getChannelCount()); + ctx.channel().close(); + } + if (cause instanceof IOException) { + // if (log.isTraceEnabled()) { + // log.trace("客户端断开链接 【{}】", ctx.channel().remoteAddress()); + // } + log.error("【{}】发生了错误: 客户端强制断开链接, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, ChannelManagerUtil.getChannelCount()); ctx.channel().close(); } // close(channelId, pileSn);