|
|
|
@ -8,6 +8,10 @@ import java.io.*;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.Socket;
|
|
|
|
import java.net.Socket;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
import java.util.concurrent.FutureTask;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* sick扫码枪
|
|
|
|
* sick扫码枪
|
|
|
|
@ -35,7 +39,7 @@ public class SickSocket {
|
|
|
|
while ("NoRead".equals(code) && i <= 4){
|
|
|
|
while ("NoRead".equals(code) && i <= 4){
|
|
|
|
Long start = System.currentTimeMillis();
|
|
|
|
Long start = System.currentTimeMillis();
|
|
|
|
writeCmd(os);
|
|
|
|
writeCmd(os);
|
|
|
|
code = read(is);
|
|
|
|
code = read(is,ip);
|
|
|
|
Long end = System.currentTimeMillis();
|
|
|
|
Long end = System.currentTimeMillis();
|
|
|
|
log.info("sick read time:{}",(end-start)/1000);
|
|
|
|
log.info("sick read time:{}",(end-start)/1000);
|
|
|
|
tcpLogger.info("count:{},ip:{},code:{}",i,ip,code);
|
|
|
|
tcpLogger.info("count:{},ip:{},code:{}",i,ip,code);
|
|
|
|
@ -81,9 +85,35 @@ public class SickSocket {
|
|
|
|
os.write(bytes);
|
|
|
|
os.write(bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String read(InputStream inStream) 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));
|
|
|
|
return bd.readLine();
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
FutureTask<StringBuilder> future = new FutureTask <>(()->{
|
|
|
|
|
|
|
|
StringBuilder bdString = new StringBuilder();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bdString.append((char) bd.read());
|
|
|
|
|
|
|
|
} catch (IOException exc) {
|
|
|
|
|
|
|
|
throw new RuntimeException(exc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bdString.toString().contains("\\n") || bdString.toString().contains("\n")) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return bdString;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
new Thread(future).start();
|
|
|
|
|
|
|
|
stringBuilder = future.get(1000, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
|
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tcpLogger.error("sick 可以连接但发送返回存在问题,ip:{},info:{}", ip, e);
|
|
|
|
|
|
|
|
log.error("sick 可以连接但发送返回存在问题,ip:{},info:{}", ip, e);
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringBuilder.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|