JLChen
2021-12-10 739d5bad0d24c5f4913f8d8e09292b5b98991fac
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLSocket.java
@@ -11,6 +11,7 @@
import com.hdl.sdk.common.exception.HDLLinkException;
import com.hdl.sdk.common.utils.IdUtils;
import com.hdl.sdk.common.utils.IpUtils;
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.SPUtils;
import com.hdl.sdk.common.utils.ThreadToolUtils;
import com.hdl.sdk.common.utils.gson.GsonConvert;
@@ -165,7 +166,10 @@
        pipeLine.add(new LinkMessageDecoder());
        pipeLine.add(new LinkMessageEncoder());
        options.setHandleMessage(pipeLine);
        options.setEnabledHeartbeat(false);
        options.setEnabledHeartbeat(false);//是否开启心跳包发送检测
//        options.setHeartbeatTimeInterval(10*1000L);
//        options.setHeartbeatData("TCP");
//        options.setEnabledHeartbeat(true);//是否开启心跳包发送检测
        return options;
    }
@@ -681,6 +685,24 @@
        }
    }
    /**
     * 通用TCP发送指令 只发一次,不监听回复,不重发
     *
     * @param topic    发送数据
     * @param bodyStr  回复的主题
     */
    public void tcpSendMsg(String topic, String bodyStr) {
        try {
            if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) {
                LogUtils.e("udpSendMsg", "参数不能为空");
                return;
            }
            LinkRequest message = new LinkRequest(topic, bodyStr);
            getTcp().sendMsg(message.getSendBytes());
        } catch (Exception e) {
            LogUtils.e("tcpSendMsg", "发送失败 :"+e.getMessage());
        }
    }
    /**
     * 发送指令
@@ -696,12 +718,14 @@
                @Override
                public void onMessage(Object msg) {
                    if (msg instanceof LinkResponse) {
                        LogUtils.e("sendMsg onSuccess");
                        if (callBack != null) {
                            callBack.onSuccess(msg.toString());
                        }
                        threadPool.shutdownNow();
                    }
                    LogUtils.e("sendMsg eventListener remove");
                    EventDispatcher.getInstance().remove(eventTag, this);
                }
            };
@@ -713,6 +737,7 @@
                        getTcp().sendMsg(data);
                    } else {
                        threadPool.shutdownNow();
                        LogUtils.e("sendMsg eventListener remove");
                        EventDispatcher.getInstance().remove(eventTag, eventListener);
                        ThreadToolUtils.getInstance().runOnUiThread(new Runnable() {
                            @Override