优化tcp超时时间

This commit is contained in:
lixiao 2025-05-15 15:10:39 +08:00
parent 2a588d5d7c
commit 7dfc959aa2
4 changed files with 4 additions and 13 deletions

View File

@ -109,12 +109,6 @@ export async function writeObjectOut(params, filePath?: string): Promise<WR> {
await fileUtil.initFolder(filePath); await fileUtil.initFolder(filePath);
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`); fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
} }
// const {code} = temp;
// if(code == '2300007' || code == '2300028'){
// return await writeObjectOut(params,filePath)
// }else{
// return temp
// }
return temp return temp
} }

View File

@ -17,7 +17,7 @@ export default class TcpClient {
//重连次数 //重连次数
private folderPath private folderPath
private tcp: any = null private tcp: socket.TCPSocket = null
constructor(tcplocalIp: string, tcplocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) { constructor(tcplocalIp: string, tcplocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) {
this.localIp = tcplocalIp this.localIp = tcplocalIp
@ -65,7 +65,7 @@ export default class TcpClient {
this.tcp.connect({ this.tcp.connect({
address: { address: {
address: this.oppositeIp, port: Number(this.oppositeIpPort), family: 1 address: this.oppositeIp, port: Number(this.oppositeIpPort), family: 1
}, timeout: 6000 }, timeout: 1000 * 15
}).then(() => { }).then(() => {
this.tcp.setExtraOptions({ this.tcp.setExtraOptions({
keepAlive: true, keepAlive: true,
@ -148,7 +148,7 @@ export default class TcpClient {
offTcp(callback) { offTcp(callback) {
console.log(TAG, 'tcpofff') console.log(TAG, 'tcpofff')
this.tcp.off('testTagofmessg', callback); this.tcp.off('message', callback);
} }
closeTcp(callback) { closeTcp(callback) {

View File

@ -342,9 +342,6 @@ export default struct SignDisplayCom {
} }
async aboutToAppear() { async aboutToAppear() {
// const fileUtil = new FileUtil(globalThis.context)
// const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt')
// this.udplocalIp=JSON.parse(data)?.udplocalIp||'192.168.7.170'
this.ratio = this.ratio * (this.scaleNum || 1); this.ratio = this.ratio * (this.scaleNum || 1);
const {showBack,getSignal} = this const {showBack,getSignal} = this

View File

@ -607,7 +607,7 @@ export default class Judge {
const temp = await writeObjectOut(data, filePath); const temp = await writeObjectOut(data, filePath);
console.log("wzj", JSON.stringify(temp)) console.log("wzj", JSON.stringify(temp))
//断网&网络超时次数计算 //断网&网络超时次数计算
if (temp.code == 2300007 || temp.code == 2300028) { if (temp.code != 1) {
this.disConnectNum += 1; this.disConnectNum += 1;
if (this.disConnectNum < 5) { if (this.disConnectNum < 5) {
return await this.sendWriteObjectOut(data, filePath) return await this.sendWriteObjectOut(data, filePath)