开机连接失败后重新连接

sick传输不用后缀加回车
chongqing-yashichuangneng
LAPTOP-S9HJSOEB\昊天 3 years ago
parent 5fb1b59bed
commit 967440bc30

@ -110,6 +110,7 @@ public class InitService implements ApplicationRunner {
ksecNettyClient.createClient(ksec); ksecNettyClient.createClient(ksec);
}catch (Exception e){ }catch (Exception e){
log.error("kesc connect error,url:{},port:{}",ksec.getIp(),ksec.getPort()); log.error("kesc connect error,url:{},port:{}",ksec.getIp(),ksec.getPort());
ksecNettyClient.reconnect(1);
} }
}else { }else {
log.error("ksec no config"); log.error("ksec no config");

@ -88,29 +88,32 @@ public class SickSocket {
private static String read(InputStream inStream,String ip) throws IOException { private static String read(InputStream inStream,String ip) throws IOException {
BufferedReader bd = new BufferedReader(new InputStreamReader(inStream)); BufferedReader bd = new BufferedReader(new InputStreamReader(inStream));
StringBuilder stringBuilder = new StringBuilder(); StringBuffer stringBuilder = new StringBuffer();
FutureTask<StringBuilder> future = new FutureTask <>(()->{ FutureTask<StringBuffer> future = new FutureTask <>(()->{
StringBuilder bdString = new StringBuilder();
while (true) { while (true) {
try { try {
bdString.append((char) bd.read()); stringBuilder.append((char) bd.read());
} catch (IOException exc) { } catch (IOException exc) {
throw new RuntimeException(exc); throw new RuntimeException(exc);
} }
if (bdString.toString().contains("\\n") || bdString.toString().contains("\n")) { if (stringBuilder.toString().contains("\\n") || stringBuilder.toString().contains("\n")) {
break; break;
} }
} }
return bdString; return stringBuilder;
}); });
try { try {
new Thread(future).start(); new Thread(future).start();
stringBuilder = future.get(1000, TimeUnit.MILLISECONDS); future.get(1000, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) { } catch (InterruptedException | ExecutionException | TimeoutException e) {
tcpLogger.error("sick 可以连接但发送返回存在问题,ip:{},info:{}", ip, e); if("".equals(stringBuilder.toString())){
log.error("sick 可以连接但发送返回存在问题,ip:{},info:{}", ip, e); tcpLogger.error("sick 可以连接但发送返回存在问题,ip:{},info:{}", ip, e);
throw new RuntimeException(e); log.error("sick 可以连接但发送返回存在问题,ip:{},info:{}", ip, e);
throw new RuntimeException(e);
}else {
return stringBuilder.toString();
}
} }
return stringBuilder.toString(); return stringBuilder.toString();
} }

Loading…
Cancel
Save