From d8bf4f4d66715f002d024cae92862c1d83daa425 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期日, 12 十二月 2021 22:06:35 +0800 Subject: [PATCH] 更改了udp的机制 --- HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java | 53 ++++++++++++++++++++++++++--------------------------- 1 files changed, 26 insertions(+), 27 deletions(-) diff --git a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java b/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java index 8d206f5..0a084ac 100644 --- a/HDLSDK/hdl-socket/src/main/java/com/hdl/sdk/socket/SocketBoot.java +++ b/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,10 @@ public void run() { while (isRun.get()) { if (client.isConnect()) { - Log.d("=====", "==鍙戦�佹暟鎹�=="); - try { SocketRequest socketRequest = mMessageQueue.take(); final String sendStr = new String(socketRequest.getData(), 0, socketRequest.getData().length); - Log.d("=====", "==鍙戦�佹暟鎹�==锛�"+sendStr); + LogUtils.i("鍙戦�佹暟鎹細"+sendStr); final String action = socketRequest.getAction(); try { client.sendMsg(socketRequest.getData()); @@ -165,34 +164,36 @@ } } - Log.d("=====", "==鍙戦�佺嚎绋嬪叧闂�=="); + LogUtils.d("=====", "==鍙戦�佺嚎绋嬪叧闂�=="); } }); } + /** + * 鍒濆鍖栨帴鏀剁嚎绋嬶紝鍙渶瑕佸垵濮嬪寲涓�娆� + */ public void initReceiveThread() { if (receiveThread == null) { receiveThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); - } - receiveThread.execute(new Runnable() { - @Override - public void run() { - while (isRun.get()) { - if (client.isConnect()) { - try { - //璇诲彇鏁版嵁 - client.onHandleResponse(); - } catch (Exception e) { - e.printStackTrace(); - Log.d("====", "鏂紑杩炴帴" + e.getMessage()); - disconnectError(); + receiveThread.execute(new Runnable() { + @Override + public void run() { + while (isRun.get()) { + if (client.isConnect()) { + try { + //璇诲彇鏁版嵁 + client.onHandleResponse(); + } catch (Exception e) { + e.printStackTrace(); + disconnectError(); + } } } + LogUtils.i("Socket 绾跨▼閫�鍑烘帴鏀舵暟鎹�"); } - } - }); - + }); + } } @@ -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) { @@ -257,7 +258,6 @@ if (!client.isConnect()) { resetConnect(false); } - } /** @@ -277,7 +277,6 @@ if (!client.isConnect() && isOpenRetry.get()) { resetConnect(false); } - } }, 3000, TimeUnit.MILLISECONDS); } -- Gitblit v1.8.0