链接普天

心跳判断链接客户端
nanjing-yancao-wuliuzhongxin-qsl
LAPTOP-S9HJSOEB\昊天 3 years ago
parent 6ea541fb2a
commit 5141c80e63

Binary file not shown.

@ -7,6 +7,7 @@ import com.zhehekeji.web.entity.Street;
import com.zhehekeji.web.mapper.StreetMapper; import com.zhehekeji.web.mapper.StreetMapper;
import com.zhehekeji.web.service.*; import com.zhehekeji.web.service.*;
import com.zhehekeji.web.service.ksec.KsecNettyClient; import com.zhehekeji.web.service.ksec.KsecNettyClient;
import com.zhehekeji.web.service.putian.PuTianNettyClient;
import com.zhehekeji.web.service.robotic.NettyClient; import com.zhehekeji.web.service.robotic.NettyClient;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -31,6 +32,8 @@ public class PLCController {
private ConfigProperties configProperties; private ConfigProperties configProperties;
@Resource @Resource
private KsecNettyClient ksecNettyClient; private KsecNettyClient ksecNettyClient;
@Resource
private PuTianNettyClient puTianNettyClient;
@GetMapping("/tcp") @GetMapping("/tcp")
@ -38,7 +41,7 @@ public class PLCController {
public Result tcp(@RequestParam Integer id){ public Result tcp(@RequestParam Integer id){
if(configProperties.getServerMode() == 1){ if(configProperties.getServerMode() == 1){
try { try {
ksecNettyClient.createClient(configProperties.getKsec()); puTianNettyClient.createClient(configProperties.getKsec());
}catch (Exception e){ }catch (Exception e){
Assert.isTrue(false,"连接失败ip"+configProperties.getKsec().getIp()+",port:"+configProperties.getKsec().getPort()); Assert.isTrue(false,"连接失败ip"+configProperties.getKsec().getIp()+",port:"+configProperties.getKsec().getPort());
} }

@ -28,4 +28,5 @@ public class CETransmission {
} }
} }
} }

@ -11,6 +11,7 @@ import java.net.InetSocketAddress;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* chanel * chanel
@ -23,20 +24,20 @@ public class ClientChanel {
/** /**
* key : * key :
*/ */
private static Map<String, Channel> channelMap = new HashMap<>(); private static Map<String, Channel> channelMap = new ConcurrentHashMap<>();
/** /**
* key :IP * key :IP
* value: * value:
*/ */
private static Map<String,String> IP_SRMNumberMap = new HashMap<>(); private static Map<String,String> IP_SRMNumberMap = new ConcurrentHashMap<>();
/** /**
* key : * key :
* value: IP * value: IP
*/ */
private static Map<String,String> SRMNumber_IPMap = new HashMap<>(); private static Map<String,String> SRMNumber_IPMap = new ConcurrentHashMap<>();
public static void putIp(String ip,String ID){ public static void putIp(String ip,String ID){
IP_SRMNumberMap.put(ip,ID); IP_SRMNumberMap.put(ip,ID);
@ -63,6 +64,7 @@ public class ClientChanel {
InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress(); InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress();
String clientIp = socketAddress.getAddress().getHostAddress(); String clientIp = socketAddress.getAddress().getHostAddress();
putSRMNUmber_Ip(SRMNumber, clientIp); putSRMNUmber_Ip(SRMNumber, clientIp);
log.info("connect 巷道 ");
} }
public static void disConnect(String key){ public static void disConnect(String key){

@ -1,6 +1,5 @@
package com.zhehekeji.web.service.client; package com.zhehekeji.web.service.client;
import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
import com.zhehekeji.web.entity.Stock; import com.zhehekeji.web.entity.Stock;
import com.zhehekeji.web.service.EmptyCheckService; import com.zhehekeji.web.service.EmptyCheckService;
import com.zhehekeji.web.service.PlcService; import com.zhehekeji.web.service.PlcService;
@ -171,6 +170,7 @@ public class Decoder extends DelimiterBasedFrameDecoder {
HBTransmission hbTransmission = new HBTransmission(body); HBTransmission hbTransmission = new HBTransmission(body);
//回复客户端心跳 //回复客户端心跳
ctx.channel().writeAndFlush(hbTransmission.toString()); ctx.channel().writeAndFlush(hbTransmission.toString());
ClientChanel.connect(hbTransmission.getSRMNumber(), ctx.channel());
//tcpLogger.info("client:{} heart", hbTransmission.getSRMNumber()); //tcpLogger.info("client:{} heart", hbTransmission.getSRMNumber());
in.release(); in.release();
} else if(body.startsWith(TMTransmission.getHeader())){ } else if(body.startsWith(TMTransmission.getHeader())){

@ -28,4 +28,9 @@ public class HBTransmission {
} }
} }
public static void main(String[] args) {
HBTransmission ceTransmission= new HBTransmission("HB&1");
System.out.println(ceTransmission);
}
} }

@ -7,7 +7,7 @@ spring:
maxWait: 60000 maxWait: 60000
minEvictableIdleTimeMillis: 300000 minEvictableIdleTimeMillis: 300000
minIdle: 15 minIdle: 15
password: Leaper@123 password: root
poolPreparedStatements: true poolPreparedStatements: true
testOnBorrow: true testOnBorrow: true
testOnReturn: false testOnReturn: false
@ -20,6 +20,10 @@ spring:
# --------本服务端口号 # --------本服务端口号
server: server:
port: 8099 port: 8099
# 服务端IP
IP: 127.0.0.1
# 服务端TCP端口
serverPort: 4000
#-------------- #--------------
# ------用户中心地址 # ------用户中心地址
userUrl: http://115.236.65.98:11001 userUrl: http://115.236.65.98:11001

Loading…
Cancel
Save