From 0c32b012859aab4e9a7a0c5e38720bdada01af26 Mon Sep 17 00:00:00 2001 From: surenjun Date: Wed, 5 Mar 2025 14:11:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=A1=A5=E5=8C=85=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/tcp2byte/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/entry/src/main/ets/tcp2byte/index.ts b/entry/src/main/ets/tcp2byte/index.ts index 5dec3f24..bbc4dcc4 100644 --- a/entry/src/main/ets/tcp2byte/index.ts +++ b/entry/src/main/ets/tcp2byte/index.ts @@ -105,17 +105,17 @@ function handReceiveMessage(client: socket.TCPSocket, sendData, rData: ArrayBuff //开始补包 if (messageType === 0xF0) { //获取消息体长度 - const messageLength = receiveData[12] + const messageLength = receiveData[13] //分包总数 - const packages = bytesToDecimal(receiveData.slice(13, 13 + messageLength * 2)); - const forArr = new Array(packages).fill(1) + const packages = receiveData.slice(14, 14 + messageLength * 2); + const forArr = new Array(messageLength).fill(1) - forArr.forEach((item, index) => { + forArr.forEach((item,index)=>{ const start = index * 2; - const end = start + 2; - const packageIndex = bytesToDecimal([start, end]); + const end = start + 1; + const packageIndex = bytesToDecimal([packages[start],packages[end]]); console.info(TAG, '补包内容' + JSON.stringify(new Uint8Array(sendData[packageIndex]))) - client.send({ data: new Uint8Array(sendData[packageIndex]).buffer }); + client.send({data:new Uint8Array(sendData[packageIndex]).buffer}); }) } else { const decoder = util.TextDecoder.create('utf-8');