diff --git a/entry/src/main/ets/tcp2byte/index.ts b/entry/src/main/ets/tcp2byte/index.ts index 8866abf6..d8c9340c 100644 --- a/entry/src/main/ets/tcp2byte/index.ts +++ b/entry/src/main/ets/tcp2byte/index.ts @@ -18,10 +18,26 @@ const config = { port: 40000 } +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)