tcp 错误判断修改
This commit is contained in:
		
							parent
							
								
									494da52f37
								
							
						
					
					
						commit
						2119758411
					
				| @ -5,9 +5,9 @@ | ||||
|         "name": "default", | ||||
|         "material": { | ||||
|           "certpath": "C:\\Users\\93218\\.ohos\\config\\openharmony\\auto_ohos_default_subject-two_com.oh.dts.cer", | ||||
|           "storePassword": "0000001A201E78D07D9BC954731E8031E587503BCABA403A7FF51995EF10FEAF0A0AEE7314A959E32BA1", | ||||
|           "storePassword": "0000001A1DDAA4ACBCE726491F94C3AF56A2540582DD64F1D58054FCE4F27EB1EA3AB9254BF5C318282B", | ||||
|           "keyAlias": "debugKey", | ||||
|           "keyPassword": "0000001ADA728F738FCA67EB2AE35E237F224EE342E5CE1591F417AB0E0CEFE20EE9585997B6D82B6CFB", | ||||
|           "keyPassword": "0000001AD378A9170F3E15A274CD444FCF00FAF0839F218288C28EC15366295413D9CB4926E710B7AEE8", | ||||
|           "profile": "C:\\Users\\93218\\.ohos\\config\\openharmony\\auto_ohos_default_subject-two_com.oh.dts.p7b", | ||||
|           "signAlg": "SHA256withECDSA", | ||||
|           "storeFile": "C:\\Users\\93218\\.ohos\\config\\openharmony\\auto_ohos_default_subject-two_com.oh.dts.p12" | ||||
|  | ||||
| @ -189,8 +189,11 @@ class TcpUtils { | ||||
|       this.requestMap.delete(key) | ||||
|       await this.socket.close() | ||||
|       this.socket = socket.constructTCPSocketInstance() | ||||
|       const fileUtil = new FileUtil(globalThis.context) | ||||
|       const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); | ||||
|       const result = JSON.parse(data) | ||||
|       await this.socket.connect({ | ||||
|         address: { address: "172.37.55.191", port: 19998 } | ||||
|         address: { address: result.tcpOppositeIp, port: 19998 } | ||||
|       }).then(res => { | ||||
|         console.log("tcp request reconnect success", JSON.stringify(res)) | ||||
|       }).catch(err => { | ||||
|  | ||||
| @ -109,7 +109,7 @@ export default async function request<T>(req: any): Promise<T> { | ||||
|   //     reject(err)
 | ||||
|   //   })
 | ||||
|   // })
 | ||||
|   return tempRequest<T>(req) | ||||
|   // return tempRequest<T>(req)
 | ||||
|   if (!isError) { | ||||
|     return new Promise<T>((resolve, reject) => { | ||||
|       console.log("[http request] url: " + req.url) | ||||
| @ -118,7 +118,7 @@ export default async function request<T>(req: any): Promise<T> { | ||||
|         console.log("[http request] http request success") | ||||
|         resolve(response) | ||||
|       }).catch((error) => { | ||||
|         isError=true | ||||
|         isError = true | ||||
|         connection.getDefaultNet((error: any, data: any) => { | ||||
|           if (error) { | ||||
|             console.error(`Failed Http. Code:${error.code}, message:${error.message}`); | ||||
| @ -141,7 +141,7 @@ export default async function request<T>(req: any): Promise<T> { | ||||
|     console.log("[http request] url: " + req.url) | ||||
|     console.log("[http request] only tcp request start") | ||||
|     return new Promise((resolve, reject) => { | ||||
|       tcpRequest(req).then(res=> { | ||||
|       tcpRequest(req).then(res => { | ||||
|         console.log("[http request] only tcp request success") | ||||
|         resolve(res as T) | ||||
|       }).catch(err => { | ||||
| @ -152,59 +152,53 @@ export default async function request<T>(req: any): Promise<T> { | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   if (!isError) { | ||||
|     return new Promise<T>((resolve, reject) => { | ||||
|       console.log("[http request] url: " + req.url) | ||||
|       console.log("[http request] tcp request start") | ||||
|       tcpRequest<T>(req).then((response) => { | ||||
|         console.log("[http request] tcp request success") | ||||
|         resolve(response) | ||||
|       }).catch((error) => { | ||||
|         isError = true | ||||
|         // vs.playAudio({
 | ||||
|         //   type: 1,
 | ||||
|         //   name: 'voice/PLCError.mp3'
 | ||||
|         // })
 | ||||
|         connection.getDefaultNet((error: any, data: any) => { | ||||
|           if (error) { | ||||
|             console.error(`Failed Http. Code:${error.code}, message:${error.message}`); | ||||
|             return; | ||||
|           } | ||||
|           console.log("Http success" + JSON.stringify(data)); | ||||
|         }); | ||||
|         console.log("[http request] tcp request error: " + JSON.stringify(error)) | ||||
|         console.log("[http request] start http resend") | ||||
|         tempRequest<T>(req).then(response => { | ||||
|           console.log("[http request] http resend success") | ||||
|           resolve(response as T) | ||||
|         }).catch(err => { | ||||
|           // vs.playAudio({
 | ||||
|           //   type: 1,
 | ||||
|           //   name: 'voice/PLCError.mp3'
 | ||||
|           // })
 | ||||
|           TempLogger.error(JSON.stringify({ | ||||
|             time: dateFormat(new Date()), | ||||
|             error: JSON.stringify(error), | ||||
|             params: JSON.stringify(req) | ||||
|           })) | ||||
|           console.log("[http request] http resend failed: " + JSON.stringify(err)) | ||||
|           reject(err) | ||||
|         }) | ||||
|       }) | ||||
|     }) | ||||
|   } else { | ||||
|     console.log("[http request] url: " + req.url) | ||||
|     console.log("[http request] only http request start") | ||||
|     return new Promise((resolve, reject) => { | ||||
|       tempRequest(req).then((response) => { | ||||
|         console.log("[http request] only http request success") | ||||
|         resolve(response as T) | ||||
|       }).catch(err => { | ||||
|         console.log("[http request] only http request error") | ||||
|         reject(err) | ||||
|       }) | ||||
|     }) | ||||
|   } | ||||
|   // if (!isError) {
 | ||||
|   //   return new Promise<T>((resolve, reject) => {
 | ||||
|   //     console.log("[http request] url: " + req.url)
 | ||||
|   //     console.log("[http request] tcp request start")
 | ||||
|   //     tcpRequest<T>(req).then((response) => {
 | ||||
|   //       console.log("[http request] tcp request success")
 | ||||
|   //       resolve(response)
 | ||||
|   //     }).catch((error) => {
 | ||||
|   //       if (error.code === 2300007) {
 | ||||
|   //         isError = true
 | ||||
|   //       }
 | ||||
|   //       connection.getDefaultNet((error: any, data: any) => {
 | ||||
|   //         if (error) {
 | ||||
|   //           console.error(`Failed Http. Code:${error.code}, message:${error.message}`);
 | ||||
|   //           return;
 | ||||
|   //         }
 | ||||
|   //         console.log("Http success" + JSON.stringify(data));
 | ||||
|   //       });
 | ||||
|   //       console.log("[http request] tcp request error: " + JSON.stringify(error))
 | ||||
|   //       console.log("[http request] start http resend")
 | ||||
|   //       tempRequest<T>(req).then(response => {
 | ||||
|   //         console.log("[http request] http resend success")
 | ||||
|   //         resolve(response as T)
 | ||||
|   //       }).catch(err => {
 | ||||
|   //         TempLogger.error(JSON.stringify({
 | ||||
|   //           time: dateFormat(new Date()),
 | ||||
|   //           error: JSON.stringify(error),
 | ||||
|   //           params: JSON.stringify(req)
 | ||||
|   //         }))
 | ||||
|   //         console.log("[http request] http resend failed: " + JSON.stringify(err))
 | ||||
|   //         reject(err)
 | ||||
|   //       })
 | ||||
|   //     })
 | ||||
|   //   })
 | ||||
|   // } else {
 | ||||
|   //   console.log("[http request] url: " + req.url)
 | ||||
|   //   console.log("[http request] only http request start")
 | ||||
|   //   return new Promise((resolve, reject) => {
 | ||||
|   //     tempRequest(req).then((response) => {
 | ||||
|   //       console.log("[http request] only http request success")
 | ||||
|   //       resolve(response as T)
 | ||||
|   //     }).catch(err => {
 | ||||
|   //       console.log("[http request] only http request error")
 | ||||
|   //       reject(err)
 | ||||
|   //     })
 | ||||
|   //   })
 | ||||
|   // }
 | ||||
| } | ||||
| 
 | ||||
| //xml格式转JSON
 | ||||
|  | ||||
| @ -1,16 +1,15 @@ | ||||
| -----BEGIN CERTIFICATE----- | ||||
| MIICFDCCAZugAwIBAgIIbCabrHLc1nQwCgYIKoZIzj0EAwMwYzELMAkGA1UEBhMC | ||||
| MIICFTCCAZugAwIBAgIIGq+f00ke04IwCgYIKoZIzj0EAwMwYzELMAkGA1UEBhMC | ||||
| Q04xFDASBgNVBAoTC09wZW5IYXJtb255MRkwFwYDVQQLExBPcGVuSGFybW9ueSBU | ||||
| ZWFtMSMwIQYDVQQDExpPcGVuSGFybW9ueSBBcHBsaWNhdGlvbiBDQTAeFw0yNTAy | ||||
| MjgwMjMwMTdaFw0zNTAyMjYwMjMwMTdaMEoxFTATBgNVBAMMDGlkZV9kZW1vX2Fw | ||||
| ZWFtMSMwIQYDVQQDExpPcGVuSGFybW9ueSBBcHBsaWNhdGlvbiBDQTAeFw0yNTAz | ||||
| MDUwNjM2NTBaFw0zNTAzMDMwNjM2NTBaMEoxFTATBgNVBAMMDGlkZV9kZW1vX2Fw | ||||
| cDENMAsGA1UECxMEVW5pdDEVMBMGA1UEChMMT3JnYW5pemF0aW9uMQswCQYDVQQG | ||||
| EwJDTjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABOFq48bclfywoLttIlG/YDMM | ||||
| Xlm2fo7BMAagThiUCBf9Bs2Bok2OZDNJiwEHaLs9u3hy0m0lzW0y2gNfoPtfxt2j | ||||
| UjBQMB0GA1UdDgQWBBTG5WaMCuxFkT65zsvOv/hX8GUPVDAOBgNVHQ8BAf8EBAMC | ||||
| EwJDTjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABE7n4JhN2eaSkLl7n4xFpDJL | ||||
| ilA9I8KIfLH8SRDUkPrXf2wJMmMtuoVVF5GJeg1PEWCtO/MnyW9bWSVS7yfjNkyj | ||||
| UjBQMB0GA1UdDgQWBBRI3RnNQafzo9IPcVxr3ojATJSILTAOBgNVHQ8BAf8EBAMC | ||||
| B4AwHwYDVR0jBBgwFoAU24a3IhbVC6FLt90le7nxBX2iLUcwCgYIKoZIzj0EAwMD | ||||
| ZwAwZAIwTQYw6FkHfu9pzL2wQLrx6+di2h/pDIWxQ+GZpx/whBbTlB0O9qL5IKqk | ||||
| YMuXDxsAAjASc4/mVZ9n/o8XAV1CnPzLAP8hdZhTUTRY6vnf+5oKrl+VQWtsfmlT | ||||
| v4R8JxW/Pf0= | ||||
| aAAwZQIxANvofcfVoWsL2NZJtI1wpWSIJDTcgZCo09raKGJKx2TlYgh3nJkBzBEh | ||||
| IWwDsdUBZQIwI6ldAid/nCS8IcipHo8LmwJql8sIZ1BdRECQdkLK+yfzni/Kmy14 | ||||
| 77svjX/mmH4f | ||||
| -----END CERTIFICATE----- | ||||
| 
 | ||||
| 73706A370E90F2232DCA48943881E8AE44A27ADFBD6C25EE22CE13ED941EEE7C | ||||
| 843EBF354F774A955869BD3344B657552D16C547E46E1F6CEDCB79CEF80628A4 | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user