fix: 暂存
This commit is contained in:
		
						commit
						32e66a83be
					
				| @ -3,7 +3,6 @@ import util from '@ohos.util' | ||||
| import promptAction from '@ohos.promptAction' | ||||
| import TcpToByte from './utils/tcp2byte' | ||||
| import {bytesToDecimal} from './utils/tools' | ||||
| 
 | ||||
| const TAG = '[TCP2BYTE]' | ||||
| 
 | ||||
| 
 | ||||
| @ -13,8 +12,8 @@ interface RES { | ||||
| } | ||||
| 
 | ||||
| const config = { | ||||
|   address: '172.37.55.191', | ||||
|   port: 40000 | ||||
|   address: '114.55.125.222', | ||||
|   port: 50189 | ||||
| } | ||||
| 
 | ||||
| export default async function tcp2ByteRequest(data): Promise<RES> { | ||||
| @ -28,11 +27,7 @@ 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) { | ||||
| @ -88,14 +83,14 @@ 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: ArrayBuffer): RES { | ||||
| function handReceiveMessage(client: socket.TCPSocket, sendData, rData:ArrayBuffer):RES { | ||||
| 
 | ||||
|   const receiveData = new Uint8Array(rData) | ||||
|   //返回的消息类型
 | ||||
|   const messageType = receiveData[1]; | ||||
|   //流水号
 | ||||
| @ -106,7 +101,7 @@ function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData: Arr | ||||
|     //获取消息体长度
 | ||||
|     const messageLength = receiveData[12] | ||||
|     //分包总数
 | ||||
|     const packages = receiveData.slice(13, 13 + messageLength * 2); | ||||
|     const packages = bytesToDecimal(receiveData.slice(13,13 + messageLength*2)); | ||||
|     const forArr = new Array(packages).fill(1) | ||||
| 
 | ||||
|     forArr.forEach((item,index)=>{ | ||||
| @ -122,7 +117,7 @@ function handReceiveMessage(client: socket.TCPSocket, sendData, receiveData: Arr | ||||
|     const markLength = receiveData[11]; | ||||
|     const markContent = decoder.decodeWithStream(receiveData.slice(12, 12 + markLength )); | ||||
|     console.info(TAG, 'markContent=>' + markContent) | ||||
|     const tipLength = receiveData[13].buffer; | ||||
|     const tipLength = receiveData[13]; | ||||
|     const messageContent = decoder.decodeWithStream(receiveData.slice(13 + markLength, 13 + markLength + tipLength)); | ||||
|     console.info(TAG, 'messageContent=>' + messageContent) | ||||
|     return { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user