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 97656d2..edc3bdb 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 @@ -16,7 +16,7 @@ public class HikLoginModuleImpl implements CameraControlLoginModule { public static HCNetSDK hcNetsdk = HCNetSDK.INSTANCE; - private static int MAX_RECONNET_TIME = 100000; + private static int MAX_RECONNET_TIME = 100; static HikExceptionCallBack hikExceptionCallBack = new HikExceptionCallBack(); diff --git a/web/src/main/java/com/zhehekeji/web/service/hikLightSource/HikControlSocket.java b/web/src/main/java/com/zhehekeji/web/service/hikLightSource/HikControlSocket.java index 1b74241..a31060e 100644 --- a/web/src/main/java/com/zhehekeji/web/service/hikLightSource/HikControlSocket.java +++ b/web/src/main/java/com/zhehekeji/web/service/hikLightSource/HikControlSocket.java @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import java.io.*; import java.net.InetSocketAddress; import java.net.Socket; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; /** @@ -18,7 +19,7 @@ public class HikControlSocket { * <${端口号},${开关状态(0:关 1:开)},${get\post}> */ public static void main(String[] args) { - String code = openLight("192.168.8.236", 2002,2,0); + String code = openLight("172.16.0.82", 9000,2,0); System.out.println(code); } @@ -29,13 +30,13 @@ public class HikControlSocket { InputStream is = null; try { socket.connect(new InetSocketAddress(ip,port),3000); + socket.setSoTimeout(10000); os = socket.getOutputStream(); + Thread.sleep(100); controlCmd(os,bool,index); is = socket.getInputStream(); - code = read(is); - if(code!= null){ - code = code.replace("\\n",""); - } + String s = read(socket.getInputStream()); + } catch (IOException e) { log.error("sick time out,ip:{},info:{}",ip,e); }finally { @@ -84,8 +85,27 @@ public class HikControlSocket { } private static String read(InputStream inStream) throws IOException { - BufferedReader bd = new BufferedReader(new InputStreamReader(inStream)); - return bd.readLine(); + StringBuffer sb = new StringBuffer(); + int start = -1; + int end = -1; + do{ + int count = inStream.available(); + if(count > 0){ + byte [] buffer = new byte[count]; + inStream.read(buffer); + String s = new String(buffer, Charset.forName("utf-8")); + sb.append(s); + System.out.println(s); + if(start < 0){ + start = sb.indexOf("<"); + } + if(end <= start){ + end = sb.indexOf(">"); + } + } + + }while (start <0 || end <= start); + return sb.substring(start,end); } }