From 811cae7eda99cdcc4988be521741af396d10829f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Fri, 2 Aug 2024 15:28:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=96=AD=E6=8E=89=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=85=B3=E6=8E=89channel=EF=BC=8C=E6=B5=B7=E5=BA=B7?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/lib/hik/HikLoginModuleImpl.java | 3 ++- .../zhehekeji/web/service/InitService.java | 3 ++- .../web/service/ksec/KsecNettyClient.java | 19 ++++++++++++++++++- web/src/main/resources/application-prod.yml | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/web/src/main/java/com/zhehekeji/web/lib/hik/HikLoginModuleImpl.java b/web/src/main/java/com/zhehekeji/web/lib/hik/HikLoginModuleImpl.java index a9b838e..57a208f 100644 --- a/web/src/main/java/com/zhehekeji/web/lib/hik/HikLoginModuleImpl.java +++ b/web/src/main/java/com/zhehekeji/web/lib/hik/HikLoginModuleImpl.java @@ -81,6 +81,7 @@ public class HikLoginModuleImpl implements CameraControlLoginModule { if(hcNetsdk.NET_DVR_Logout_V30(CameraConnMap.getConnId(cameraId).intValue())) { log.error("hik cameraId:{}注销",cameraId); + hcNetsdk.NET_DVR_Cleanup(); } } @@ -101,7 +102,7 @@ public class HikLoginModuleImpl implements CameraControlLoginModule { m_strLoginInfo.wPort = (short) m_nPort; - m_strLoginInfo.bUseAsynLogin = true; //是否异步登录:0- 否,1- 是 + m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是 m_strLoginInfo.write(); HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo30 = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//设备信息 diff --git a/web/src/main/java/com/zhehekeji/web/service/InitService.java b/web/src/main/java/com/zhehekeji/web/service/InitService.java index 6a5d3b4..35d6dad 100644 --- a/web/src/main/java/com/zhehekeji/web/service/InitService.java +++ b/web/src/main/java/com/zhehekeji/web/service/InitService.java @@ -88,6 +88,8 @@ public class InitService implements ApplicationRunner { CameraConnMap.cameraByIdMap.put(camera.getId(),camera); }); LPLicense.createLicKeyIfNotExist(); + + TaskDelayExecutor.runMp4DownloadExecutor(); //plc连接 if(configProperties.getServerMode() == 0){ log.info("PLC TCP MODE"); @@ -118,7 +120,6 @@ public class InitService implements ApplicationRunner { log.error("ksec no config"); } } - TaskDelayExecutor.runMp4DownloadExecutor(); } class LoginThread extends Thread{ diff --git a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java index 8b24209..3e615ee 100644 --- a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java +++ b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java @@ -6,6 +6,8 @@ import com.zhehekeji.web.config.ConfigProperties; import com.zhehekeji.web.service.PlcService; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; @@ -14,6 +16,8 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import javax.annotation.Resource; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; @Slf4j @Component @@ -28,6 +32,7 @@ public class KsecNettyClient { private static Channel channel; public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException { + String lotnum = FileUtil.getText("lastLotnum"); if(lotnum != null){ KsecDecoder.setLastLotnum(lotnum); @@ -41,7 +46,18 @@ public class KsecNettyClient { KsecInfo heart = KsecInfo.heart(); client.handler(new KescFilter(heart, plcService,this)); // 连接服务端 - channel = client.connect(ksec.getIp(), ksec.getPort()).sync().channel(); + + ChannelFuture future = client.connect(ksec.getIp(), ksec.getPort()).sync(); + channel = future.channel(); + future.addListener((ChannelFutureListener) future1 -> { + if (!future1.isSuccess()) { + System.err.println("Connection attempt failed"); + future1.cause().printStackTrace(); + } + }); + + future.channel().closeFuture().sync(); + } /** @@ -93,6 +109,7 @@ public class KsecNettyClient { } else { log.error("plc reconnect error .upPcId:{},reconnect num:{},ip:{},port:{}", upId, num, ksec.getIp(), ksec.getPort()); } + } public static void write(KsecInfo ksecInfo){ diff --git a/web/src/main/resources/application-prod.yml b/web/src/main/resources/application-prod.yml index c3fe834..830f4ea 100644 --- a/web/src/main/resources/application-prod.yml +++ b/web/src/main/resources/application-prod.yml @@ -69,7 +69,7 @@ ksec: #断点重连的次数:-1->不断重连 reconnectNum: -1 #断点重连的时间间隔(单位:ms) - reconnectInterval: 10000 + reconnectInterval: 200 # ------------ 实时视频流 全部页面的格式 行列数量 videoStyleConfig: videoStyleRow: 4