fix: 暂存
This commit is contained in:
parent
21dec3fff1
commit
5d367da241
@ -3,6 +3,7 @@ import util from '@ohos.util'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import TcpToByte from './utils/tcp2byte'
|
||||
import { bytesToDecimal } from './utils/tools'
|
||||
|
||||
const TAG = '[TCP2BYTE]'
|
||||
|
||||
|
||||
@ -12,8 +13,8 @@ interface RES {
|
||||
}
|
||||
|
||||
const config = {
|
||||
address: '114.55.125.222',
|
||||
port: 50189
|
||||
address: '172.37.55.191',
|
||||
port: 40000
|
||||
}
|
||||
|
||||
export default async function tcp2ByteRequest(data): Promise<RES> {
|
||||
@ -27,7 +28,11 @@ export default async function tcp2ByteRequest(data): Promise<RES> {
|
||||
console.info(TAG, 'sendData=>' + JSON.stringify(sendData))
|
||||
|
||||
try {
|
||||
await tcpClient.connect({address: {address, port}})
|
||||
await tcpClient.connect({
|
||||
address: {
|
||||
address, port
|
||||
}
|
||||
})
|
||||
//发送消息
|
||||
handSendMessage(tcpClient, data.sjbs, sendData)
|
||||
} catch (e) {
|
||||
@ -83,12 +88,13 @@ function handSendMessage(client: socket.TCPSocket, type, data) {
|
||||
client.send({ data: new Uint8Array(data).buffer })
|
||||
break;
|
||||
|
||||
default:break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//处理接收的数据
|
||||
function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData):RES {
|
||||
function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData: ArrayBuffer): RES {
|
||||
|
||||
//返回的消息类型
|
||||
const messageType = receiveData[1];
|
||||
@ -113,7 +119,7 @@ function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData):RES
|
||||
} else {
|
||||
const decoder = util.TextDecoder.create('utf-8');
|
||||
const messageLength = bytesToDecimal([receiveData[9], receiveData[10]]);
|
||||
const markLength = receiveData[11].buffer;
|
||||
const markLength = receiveData[11];
|
||||
const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength));
|
||||
console.info(TAG, 'markContent=>' + markContent)
|
||||
const tipLength = receiveData[13].buffer;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user