From 5428935270159bfc42c2934ed7fb1091554fc9a4 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期四, 09 七月 2020 17:12:42 +0800 Subject: [PATCH] 修改了 sokect --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 36 insertions(+), 17 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs index f2f87b9..002e5a4 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -32,7 +32,10 @@ { return; } - isInited = true; + isInited = true; + + //鍒濆鍖朣ocket + FindGateWaySocket.Start(); new System.Threading.Thread(async () => { @@ -96,7 +99,6 @@ var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress; - if (Shared.Application.IsWifi) { if (0 < gateWayList.Count) @@ -151,11 +153,7 @@ FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes); } } - catch - { - //鍏抽棴Socket,涓嬫鍙戦�佷細鑷姩杩炴帴 - FindGateWaySocket.Stop(); - } + catch{} System.Threading.Thread.Sleep(500); } }) @@ -173,7 +171,6 @@ var bytes = new byte[1024]; var len = FindGateWaySocket.busSocket.Receive(bytes, bytes.Length, System.Net.Sockets.SocketFlags.None); - if (bytes[43] == 0xA2) { //骞挎挱鍥炲缃戝叧鐨勫熀鏈俊鎭鐞� @@ -281,12 +278,17 @@ } } } + else + { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + var data33 = Encoding.UTF8.GetString(bytes).Replace("锟�)", string.Empty).TrimStart('\0').TrimEnd('\0'); + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, data33); + } + } } - catch - { - //鍏抽棴Socket,涓嬫鍙戦�佷細鑷姩杩炴帴 - FindGateWaySocket.Stop(); - } + catch{} } #endregion } @@ -387,10 +389,20 @@ { try { - Start(7624); - busSocket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, iPEndPoint, new AsyncCallback(asyncEndSend), null); + if (IsRunning) + { + busSocket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, iPEndPoint, new AsyncCallback(asyncEndSend), null); + } + } - catch { } + catch (Exception ex) + { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "鍙戦�佸紓甯�(BeginSendTo)\r\n" + ex.Message); + } + } } /// <summary> @@ -403,7 +415,14 @@ { int bytesSent = busSocket.EndSendTo(iar); } - catch { } + catch(Exception ex) + { + //璋冭瘯鐢� + if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "寮傛鍙戦�佺粨鏉熷紓甯�(asyncEndSend)\r\n" + ex.Message); + } + } } } } -- Gitblit v1.8.0