#
Junjie
4 天以前 ce511a3d55e5f349b1647172e562c1659bbc8172
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -15,6 +15,7 @@
import com.zy.core.enums.SlaveType;
import com.zy.core.thread.ShuttleThread;
import com.zy.core.utils.FakeDeviceUtils;
import com.zy.core.utils.TimeoutExecutor;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
@@ -24,6 +25,7 @@
import java.net.SocketTimeoutException;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Slf4j
@SuppressWarnings("all")
@@ -54,9 +56,15 @@
                try {
                    this.connect();
                    // 在循环中使用
                    boolean result = TimeoutExecutor.executeWithTimeout(
                            () -> this.listenSocketMessage(),
                            30,  // 30秒超时
                            TimeUnit.SECONDS
                    );
                    Thread.sleep(200);
                    listenSocketMessage();
                } catch (Exception e) {
                    closeSocket();
                    e.printStackTrace();
                }
            }
@@ -131,11 +139,11 @@
        }
    }
    private void listenSocketMessage() {
    private boolean listenSocketMessage() {
        StringBuffer sb = new StringBuffer();
        try {
            if (this.socket == null) {
                return;
                return false;
            }
            DeviceMsgUtils deviceMsgUtils = null;
@@ -144,7 +152,7 @@
            } catch (Exception e) {
            }
            if (deviceMsgUtils == null) {
                return;
                return false;
            }
            // 获取输入流
@@ -168,7 +176,7 @@
            }catch (Exception e){}
            if(result == null) {
                return;
                return false;
            }
            JSONObject header = null;
@@ -225,11 +233,13 @@
                }
            }
        } catch (SocketTimeoutException e) {
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            closeSocket();
            return false;
        }
        return true;
    }
    public JSONObject parseSocketResult(JSONObject data) {
@@ -292,6 +302,8 @@
                return false;
            }
            this.lastConnectTime = System.currentTimeMillis();
            if(this.deviceConfig.getFake()) {
                return fakeConnect();
            }else {
@@ -301,7 +313,6 @@
                    deviceSocket.setSoTimeout(10000);
                    deviceSocket.setKeepAlive(true);
                    this.socket = deviceSocket;
                    this.lastConnectTime = System.currentTimeMillis();
                    log.info(MessageFormat.format("【{0}】四向穿梭车Socket链接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
                }
            }