From 6a2fb2e902e0020806d1fbdbf9c47551e8c20f01 Mon Sep 17 00:00:00 2001 From: surenjun Date: Wed, 5 Mar 2025 19:44:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=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 | 18 +++++++++++++++++- entry/src/main/ets/tcp2byte/utils/tcp2byte.ts | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/entry/src/main/ets/tcp2byte/index.ts b/entry/src/main/ets/tcp2byte/index.ts index f5fb2c73..5b9ed512 100644 --- a/entry/src/main/ets/tcp2byte/index.ts +++ b/entry/src/main/ets/tcp2byte/index.ts @@ -17,10 +17,26 @@ const config = { port: 50189 } +const singleTcpClient = (function () { + let instance; + function createInstance() { + return socket.constructTCPSocketInstance() + } + + return { + getClient: function () { + if (!instance) { + instance = createInstance(); + } + return instance + } + }; +})(); + export default async function tcp2ByteRequest(data): Promise { return new Promise(async (resolve, reject) => { - const tcpClient: socket.TCPSocket = socket.constructTCPSocketInstance() + const tcpClient: socket.TCPSocket = singleTcpClient.getClient() const {address,port} = config const tcp2Byte = new TcpToByte() diff --git a/entry/src/main/ets/tcp2byte/utils/tcp2byte.ts b/entry/src/main/ets/tcp2byte/utils/tcp2byte.ts index b77ded2a..57a46c64 100644 --- a/entry/src/main/ets/tcp2byte/utils/tcp2byte.ts +++ b/entry/src/main/ets/tcp2byte/utils/tcp2byte.ts @@ -324,7 +324,7 @@ export default class TcpToByte { //考试路线 const ksxl = str2UTF8(temp.ksxl) //考车号码 - const kchp = str2UTF8(temp.kchp) + // const kchp = str2UTF8(temp.kchp) const time = timeTOBCD(temp.jssj)