| | |
| | | /// 记录接收到的消息,方便zb的工程师调试他们的设备 |
| | | /// </summary> |
| | | public List<string> MsgInfoList = new List<string>(); |
| | | private bool _LocalTcpClientLogin = false; |
| | | /// <summary> |
| | | /// 本地tcp客户端连接是否成功 |
| | | /// 是否登录网关成功 |
| | | /// </summary> |
| | | public bool LocalTcpClientLogin = false; |
| | | public bool LocalTcpClientLogin |
| | | { |
| | | get |
| | | { |
| | | return _LocalTcpClientLogin; |
| | | } |
| | | set |
| | | { |
| | | _LocalTcpClientLogin = value; |
| | | if (!value) |
| | | { |
| | | loginGatewayThread?.Abort(); |
| | | loginGatewayThread = null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | int _msg_id = 1; |
| | | /// <summary> |
| | |
| | | if (myTcpClient == null) |
| | | { |
| | | myTcpClient = new Control_TcpClient(reportIp); |
| | | myTcpClient.Connect(); |
| | | } |
| | | myTcpClient.Connect(); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if(loginGatewayThread== null) |
| | | { |
| | | loginGatewayThread = new System.Threading.Thread(() => { |
| | | while (true) |
| | | while (!Ins.myTcpClient.isConnected) |
| | | { |
| | | if (Ins.GatewayOnline_Local && myTcpClient.isConnected && LocalTcpClientLogin) |
| | | if (Ins.GatewayOnline_Local && myTcpClient.isConnected) |
| | | { |
| | | var sendData = new { clientType = "app", version = "1.0" }; |
| | | var sendJob = new { id = Control.Ins.msg_id.ToString(), time_stamp = Utlis.GetTimestamp(), objects = sendData }; |
| | |
| | | } |
| | | System.Threading.Thread.Sleep(2000); |
| | | } |
| | | //loginGatewayThread?.Abort(); |
| | | //loginGatewayThread = null; |
| | | |
| | | }); |
| | | loginGatewayThread.Start(); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | loginGatewayThread?.Abort(); |
| | | }catch (Exception ex) |
| | | { |
| | | MainPage.Log($"重启登录网关线程异常:{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | loginGatewayThread = null; |
| | | LoginGateway(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | LocalCommunicationData receiveObj = new LocalCommunicationData(); |
| | | |
| | | MainPage.Log($"局域网信息: \r\n{receiveString}"); |
| | | |
| | | var res = receiveString.Split("\r\n\r\n"); |
| | | |
| | |
| | | //} |
| | | receiveObj.BodyDataString = res[1]; |
| | | |
| | | if(receiveObj.Topic == CommunicationTopic.ct.HeartBeat) |
| | | if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply") |
| | | { |
| | | |
| | | Ins.myTcpClient.ClearHeartBeatLog(); |
| | | MainPage.Log("tcp心跳回复"); |
| | | return null; |
| | | } |
| | | |
| | |
| | | //判断当前网关是否开启了本地加密 |
| | | if (IsLocalEncryptAndGetAesKey) |
| | | { |
| | | MainPage.Log($"局域网信息 开始解密"); |
| | | if (originalReceiveBytes != null) |
| | | { |
| | | //拿到原始Bytes数据去解密 |
| | |
| | | //MainPage.Log($"局域网信息: 解密后:" + receiveObj.BodyDataString); |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"局域网信息: 明文:" + receiveObj.BodyDataString); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | OpenTcpClent(); |
| | | |
| | | LoginGateway(); |
| | | |
| | | } |
| | | } |
| | |
| | | if (temp.GetValue("objects").ToString().Contains("success")) |
| | | { |
| | | LocalTcpClientLogin = true; |
| | | try |
| | | { |
| | | loginGatewayThread?.Abort(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"终止登录网关tcp异常:{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | loginGatewayThread = null; |
| | | } |
| | | MainPage.Log("局域网tcp连接登录网关成功"); |
| | | } |
| | | } |
| | | else |