Compare commits
No commits in common. "8b915c2465eb25b0e3bfd72b1ce0f4cd1a6b5a3f" and "9dd3b845349596fb92836befc0b50299d406739c" have entirely different histories.
8b915c2465
...
9dd3b84534
@ -4,7 +4,6 @@ import hilog from '@ohos.hilog';
|
||||
import FileUtil from '../../common/utils/File'
|
||||
import { GlobalConfig } from '../../config/index'
|
||||
export async function getTCP(flag=false) {
|
||||
globalThis.getCloseTcp=true
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
if (data === '' || data === undefined) {
|
||||
@ -23,17 +22,6 @@ export async function getTCP(flag=false) {
|
||||
await globalThis.TcpClient.bindTcp()
|
||||
// await globalThis.TcpClient.rebindTcp(result.tcplocalIp, result.tcplocalIpPort, result.tcpOppositeIp, result.tcpOppositePort)
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
console.log('ttttttt0')
|
||||
// await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
console.log('ttttttt00')
|
||||
|
||||
clearInterval(globalThis.intervalSendmsg)
|
||||
globalThis.intervalSendmsg=setInterval(()=>{
|
||||
console.log('getCloseTcp',globalThis.carInfo.carNo)
|
||||
if(!globalThis.getCloseTcp){
|
||||
globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
}
|
||||
},1000/3)
|
||||
globalThis.TcpClient.onError((val) => {
|
||||
setTimeout(() => {
|
||||
getTCP()
|
||||
@ -58,13 +46,9 @@ export async function getTCP(flag=false) {
|
||||
globalThis.TcpClient = tcpClient
|
||||
await globalThis.TcpClient.bindTcp()
|
||||
await globalThis.TcpClient.connectTcp()
|
||||
console.log('ttttttt1')
|
||||
await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
console.log('ttttttt12')
|
||||
|
||||
clearInterval(globalThis.intervalSendmsg)
|
||||
globalThis.intervalSendmsg=setInterval(()=>{
|
||||
// console.log('getCloseTcp',globalThis.getCloseTcp)
|
||||
if(!globalThis.getCloseTcp){
|
||||
globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
|
||||
}
|
||||
|
||||
@ -33,12 +33,13 @@ export default class TcpClient {
|
||||
// time:dateFormat(new Date()),
|
||||
// PLC:`${TAG} tcpOnerror ${JSON.stringify(err)}`,
|
||||
// })
|
||||
console.log(TAG, 'getCloseTtcpOnerror0000', JSON.stringify(err))
|
||||
|
||||
globalThis.getCloseTcp = true
|
||||
|
||||
|
||||
console.log(TAG, 'getCloseTtcpOnerror', JSON.stringify(err))
|
||||
this.writeLog({
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcponerror localIp${JSON.stringify(err)}`,
|
||||
})
|
||||
console.log(TAG, 'tcpOnerror', JSON.stringify(err))
|
||||
setTimeout(async () => {
|
||||
getTCP()
|
||||
}, 2000)
|
||||
@ -48,7 +49,46 @@ export default class TcpClient {
|
||||
});
|
||||
}
|
||||
|
||||
rebindTcp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.localIp = localIp
|
||||
this.oppositeIp = oppositeIp
|
||||
this.localIpPort = localIpPort
|
||||
this.oppositeIpPort = oppositeIpPort
|
||||
console.log(TAG, 'tcpreBind', this.localIp, this.localIpPort)
|
||||
let promise = this.tcp.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
}, err => {
|
||||
if (err) {
|
||||
this.writeLog({
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcprebind tcpreBinderror${JSON.stringify(err)}`,
|
||||
})
|
||||
setTimeout(async () => {
|
||||
getTCP()
|
||||
}, 2000)
|
||||
// globalThis.getCloseTcp = true
|
||||
hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err));
|
||||
resolve(true)
|
||||
}
|
||||
this.writeLog({
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcprebind success`,
|
||||
})
|
||||
console.log('testTag,rebindtestTag tcp bind success');
|
||||
// globalThis.getCloseTcp = false
|
||||
resolve(false)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
// let promise = this.udp.bind({
|
||||
// // address: '192.168.7.170', port: 20122, family: 1
|
||||
// // address: '192.168.7.170', port: 31013, family: 1
|
||||
// address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
bindTcp() {
|
||||
this.writeLog({
|
||||
@ -61,6 +101,10 @@ export default class TcpClient {
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
}, err => {
|
||||
if (err) {
|
||||
// this.writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
// PLC:`${TAG} testTag tcp bind faile ${JSON.stringify(err)}`,
|
||||
// })
|
||||
this.writeLog({
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcpbind error ${JSON.stringify(err)}`,
|
||||
@ -68,14 +112,12 @@ export default class TcpClient {
|
||||
setTimeout(async () => {
|
||||
getTCP()
|
||||
}, 2000)
|
||||
console.log('getCloseTBinderror');
|
||||
console.log('testTag tcp bind faile');
|
||||
hilog.info(0x0000, 'testTag', "tcpBinderror:" + JSON.stringify(err));
|
||||
resolve(true)
|
||||
return
|
||||
}
|
||||
console.log('getCloseTBindsuccess');
|
||||
|
||||
// console.log('testTag tcp bind success');
|
||||
console.log('testTag tcp bind success');
|
||||
// this.writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
// PLC:`${TAG} testTag tcp bind success`,
|
||||
@ -83,6 +125,14 @@ export default class TcpClient {
|
||||
resolve(false)
|
||||
})
|
||||
})
|
||||
console.log('localIp', this.localIp)
|
||||
console.log('localIpPort', this.localIpPort)
|
||||
// let promise = this.udp.bind({
|
||||
// // address: '192.168.7.170', port: 20122, family: 1
|
||||
// // address: '192.168.7.170', port: 31013, family: 1
|
||||
// address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -104,21 +154,28 @@ export default class TcpClient {
|
||||
keepAlive: true,
|
||||
}, err => {
|
||||
if (err) {
|
||||
console.log('getCloseTconnectsuccess','error',globalThis.getCloseTcp)
|
||||
this.writeLog({
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} TCPconnect error ${JSON.stringify(err)}`,
|
||||
})
|
||||
|
||||
// this.writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
// PLC:`${TAG} tcp connect rebind success`,
|
||||
// })
|
||||
|
||||
setTimeout(() => {
|
||||
this.writeLog({
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcp重连`,
|
||||
})
|
||||
getTCP()
|
||||
resolve(false)
|
||||
}, 9000)
|
||||
return;
|
||||
}
|
||||
});
|
||||
console.log('getCloseTconnectsuccess');
|
||||
|
||||
console.log('getCloseTcpsocketTagconnect','success',globalThis.getCloseTcp)
|
||||
console.log('socketTag','success')
|
||||
globalThis.getCloseTcp = false
|
||||
resolve(true)
|
||||
}).catch(err => {
|
||||
@ -150,14 +207,6 @@ export default class TcpClient {
|
||||
promise.then(() => {
|
||||
reslove(true)
|
||||
}).catch(err => {
|
||||
|
||||
if(!globalThis.getCloseTcp){
|
||||
setTimeout(async () => {
|
||||
getTCP(true)
|
||||
}, 3000)
|
||||
return
|
||||
}
|
||||
globalThis.getCloseTcp=true
|
||||
console.log(`${TAG} TCPsend error ${JSON.stringify(err)}`)
|
||||
// this.writeLog({
|
||||
// time:dateFormat(new Date()),
|
||||
@ -221,6 +270,8 @@ export default class TcpClient {
|
||||
}
|
||||
offTcp(callback) {
|
||||
console.log(TAG, 'tcpofff')
|
||||
|
||||
|
||||
this.tcp.off('testTagofmessg', callback);
|
||||
}
|
||||
|
||||
@ -234,8 +285,6 @@ export default class TcpClient {
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcp closeSuccess`,
|
||||
})
|
||||
console.log('getCloseTcpsocketTagclose','success',globalThis.getCloseTcp)
|
||||
|
||||
console.log(TAG, 'tcpCloseSuccess')
|
||||
callback()
|
||||
reslove(true)
|
||||
@ -247,8 +296,6 @@ export default class TcpClient {
|
||||
time:dateFormat(new Date()),
|
||||
message: `${TAG} tcpclose error ${JSON.stringify(err)}`,
|
||||
})
|
||||
console.log('getCloseTcpsocketTagclose','error',globalThis.getCloseTcp)
|
||||
|
||||
reslove(false)
|
||||
});
|
||||
})
|
||||
|
||||
@ -466,7 +466,7 @@ struct Index {
|
||||
globalThis.singlePlay = false
|
||||
}
|
||||
this.isSingle = globalThis.singlePlay
|
||||
// this.loading = false
|
||||
this.loading = false
|
||||
this.createAlbum()
|
||||
this.num = 0
|
||||
// const TcpClient: TcpClient =new TcpClient(result[0].tcplocalIp, result[0].tcplocalIpPort,result[0].tcpOppositeIp,result[0].tcpOppositePort)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user