JLChen
2021-11-16 a4246a571c78ac6c46e7bf7dbfc123b7148caed8
HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java
@@ -5,6 +5,7 @@
import androidx.collection.ArrayMap;
import com.hdl.sdk.common.utils.LogUtils;
import com.hdl.sdk.common.utils.ThreadToolUtils;
import com.hdl.sdk.socket.annotation.ConnectStatus;
import com.hdl.sdk.socket.client.IClient;
@@ -67,7 +68,7 @@
        final int maxRetry = client.getOptions().getMaxRetry();
        if (maxRetry == 0 && resendCount.get() > 0 ||
                (maxRetry > 0 && maxRetry + 1 < resendCount.get())) {
            Log.d("====", "===重连次数达到最大==");
            LogUtils.d("====", "===重连次数达到最大==");
            return;
        }
        if (!client.isConnect()) {
@@ -82,7 +83,7 @@
                        try {
                            resendCount.set(resendCount.get() + 1);
                            Thread.sleep(300L);
                            Log.d("====", "==重连第" + resendCount + "次==");
                            LogUtils.d("====", "==重连第" + resendCount + "次==");
                        } catch (Exception ignored) {
                        }
                    }
@@ -90,7 +91,7 @@
                        client.connect();
                        isRun.set(true);
                        if (client.isConnect()) {
                            Log.d("====", "====连接成功====");
                            LogUtils.d("====", "====连接成功====");
                            startHeartbeat();
                            initSendThread();
@@ -103,7 +104,7 @@
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.d("====", "===连接失败===" + e);
                        LogUtils.d("====", "===连接失败===" + e);
                        //再判断一下有没有连接
                        if (!client.isConnect()) {
                            isRun.set(false);
@@ -126,12 +127,12 @@
            public void run() {
                while (isRun.get()) {
                    if (client.isConnect()) {
                        Log.d("=====", "==发送数据==");
                        LogUtils.d("=====", "==发送数据==");
                        try {
                            SocketRequest socketRequest = mMessageQueue.take();
                            final String sendStr = new String(socketRequest.getData(), 0, socketRequest.getData().length);
                            Log.d("=====", "==发送数据==:"+sendStr);
                            LogUtils.d("=====", "==发送数据==:"+sendStr);
                            final String action = socketRequest.getAction();
                            try {
                                client.sendMsg(socketRequest.getData());
@@ -165,7 +166,7 @@
                    }
                }
                Log.d("=====", "==发送线程关闭==");
                LogUtils.d("=====", "==发送线程关闭==");
            }
        });
@@ -185,7 +186,7 @@
                            client.onHandleResponse();
                        } catch (Exception e) {
                            e.printStackTrace();
                            Log.d("====", "断开连接" + e.getMessage());
                            LogUtils.d("====", "断开连接" + e.getMessage());
                            disconnectError();
                        }
                    }
@@ -208,7 +209,7 @@
            @Override
            public void run() {
                if (isRun.get()) {
                    Log.d("====", "===发送心跳包===");
                    LogUtils.d("====", "===发送心跳包===");
                    if (client.getOptions() != null) {
                        final byte[] heartBeat = client.getOptions().getHeartbeatData();
                        if (heartBeat != null) {