连接断掉自动关掉channel,海康同步登录

焦作-mxbc-北起
LAPTOP-S9HJSOEB\昊天 2 years ago
parent 287626e929
commit 811cae7eda

@ -81,6 +81,7 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
if(hcNetsdk.NET_DVR_Logout_V30(CameraConnMap.getConnId(cameraId).intValue())) { if(hcNetsdk.NET_DVR_Logout_V30(CameraConnMap.getConnId(cameraId).intValue())) {
log.error("hik cameraId:{}注销",cameraId); 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.wPort = (short) m_nPort;
m_strLoginInfo.bUseAsynLogin = true; //是否异步登录0- 否1- 是 m_strLoginInfo.bUseAsynLogin = false; //是否异步登录0- 否1- 是
m_strLoginInfo.write(); m_strLoginInfo.write();
HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo30 = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//设备信息 HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo30 = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//设备信息

@ -88,6 +88,8 @@ public class InitService implements ApplicationRunner {
CameraConnMap.cameraByIdMap.put(camera.getId(),camera); CameraConnMap.cameraByIdMap.put(camera.getId(),camera);
}); });
LPLicense.createLicKeyIfNotExist(); LPLicense.createLicKeyIfNotExist();
TaskDelayExecutor.runMp4DownloadExecutor();
//plc连接 //plc连接
if(configProperties.getServerMode() == 0){ if(configProperties.getServerMode() == 0){
log.info("PLC TCP MODE"); log.info("PLC TCP MODE");
@ -118,7 +120,6 @@ public class InitService implements ApplicationRunner {
log.error("ksec no config"); log.error("ksec no config");
} }
} }
TaskDelayExecutor.runMp4DownloadExecutor();
} }
class LoginThread extends Thread{ class LoginThread extends Thread{

@ -6,6 +6,8 @@ import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.service.PlcService; import com.zhehekeji.web.service.PlcService;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
@ -14,6 +16,8 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j @Slf4j
@Component @Component
@ -28,6 +32,7 @@ public class KsecNettyClient {
private static Channel channel; private static Channel channel;
public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException { public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException {
String lotnum = FileUtil.getText("lastLotnum"); String lotnum = FileUtil.getText("lastLotnum");
if(lotnum != null){ if(lotnum != null){
KsecDecoder.setLastLotnum(lotnum); KsecDecoder.setLastLotnum(lotnum);
@ -41,7 +46,18 @@ public class KsecNettyClient {
KsecInfo heart = KsecInfo.heart(); KsecInfo heart = KsecInfo.heart();
client.handler(new KescFilter(heart, plcService,this)); 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 { } else {
log.error("plc reconnect error .upPcId:{},reconnect num:{},ip:{},port:{}", upId, num, ksec.getIp(), ksec.getPort()); log.error("plc reconnect error .upPcId:{},reconnect num:{},ip:{},port:{}", upId, num, ksec.getIp(), ksec.getPort());
} }
} }
public static void write(KsecInfo ksecInfo){ public static void write(KsecInfo ksecInfo){

@ -69,7 +69,7 @@ ksec:
#断点重连的次数:-1->不断重连 #断点重连的次数:-1->不断重连
reconnectNum: -1 reconnectNum: -1
#断点重连的时间间隔(单位ms) #断点重连的时间间隔(单位ms)
reconnectInterval: 10000 reconnectInterval: 200
# ------------ 实时视频流 全部页面的格式 行列数量 # ------------ 实时视频流 全部页面的格式 行列数量
videoStyleConfig: videoStyleConfig:
videoStyleRow: 4 videoStyleRow: 4

Loading…
Cancel
Save