Skip to content

Commit 0e59f08

Browse files
sevenhhesevenhhe
authored andcommitted
腾讯连连 sdk 循环重发、重连问题修复
Change-Id: I5ceb5d4eac40a87d013c8943e482359ac354af7b
1 parent b5e093b commit 0e59f08

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/auth/socket/WSClientManager.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.tencent.iot.explorer.link.core.auth.socket
22

33
import android.text.TextUtils
4-
import com.tencent.iot.explorer.link.core.auth.IoTAuth
54
import com.tencent.iot.explorer.link.core.auth.message.MessageConst
65
import com.tencent.iot.explorer.link.core.auth.message.payload.Payload
76
import com.tencent.iot.explorer.link.core.auth.message.resp.RespFailMessage
@@ -14,7 +13,6 @@ import com.tencent.iot.explorer.link.core.auth.socket.entity.RequestEntity
1413
import com.tencent.iot.explorer.link.core.auth.util.WifiUtil
1514
import com.tencent.iot.explorer.link.core.log.L
1615
import kotlinx.coroutines.*
17-
import org.json.JSONObject
1816
import java.net.URI
1917
import java.util.*
2018

@@ -23,6 +21,7 @@ import java.util.*
2321
*/
2422
internal class WSClientManager private constructor() {
2523

24+
private var TAG = WSClientManager.javaClass.simpleName
2625
private var hasListener = false
2726
private var job: Job? = null
2827
private lateinit var heartJob: Job
@@ -340,6 +339,11 @@ internal class WSClientManager private constructor() {
340339
* 发送消息,不做消息回复确认
341340
*/
342341
fun sendMessage(message: String) {
342+
if (message == null) { // 空消息不做发送处理,且不入队列
343+
L.e(TAG, "empty message")
344+
return
345+
}
346+
343347
try {
344348
client?.run {
345349
if (isConnected) {
@@ -388,13 +392,19 @@ internal class WSClientManager private constructor() {
388392
private fun resend() {
389393
client?.run {
390394
confirmQueue.forEach {
391-
send(it.iotMsg.toString())
395+
it.iotMsg.toString()?.let { content -> // 避免发送空内容
396+
send(content)
397+
}
392398
}
393399
while (requestQueue.isNotEmpty()) {
394-
send(requestQueue.poll()?.iotMsg.toString())
400+
requestQueue.poll()?.iotMsg.toString()?.let { content -> // 避免发送空内容
401+
send(content)
402+
}
395403
}
396404
while (messageList.isNotEmpty()) {
397-
send(messageList.poll())
405+
messageList.poll()?.let { content -> // 避免发送空内容
406+
send(content)
407+
}
398408
}
399409
}
400410
}

0 commit comments

Comments
 (0)