From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期四, 17 十二月 2020 09:07:13 +0800 Subject: [PATCH] 新云端Ver1.3 --- ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs index 1e13399..e549d19 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/Application.cs @@ -69,6 +69,7 @@ new System.Threading.Thread(() => { var broadBytes = new byte[44]; + var waitCount = 0; while (true) { @@ -110,6 +111,7 @@ if (listReceiveIP.Count > 0) { + waitCount = 0; //灞�鍩熺綉鑳藉骞挎挱寰楀埌缃戝叧 ZbGateway.IsRemote = false; //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� @@ -117,6 +119,13 @@ } else { + waitCount++; + if (waitCount >= 2) + { + //涓ゆ閮芥悳涓嶅埌,鎵嶆爣璁颁负杩滅▼ + continue; + } + waitCount = 0; //灞�鍩熺綉骞挎挱涓嶅埌缃戝叧 ZbGateway.IsRemote = true; //褰撶綉鍏崇殑杩炴帴鏂瑰紡鏀瑰彉鏃�,璁板綍褰撳墠鐨勮繛鎺ユ柟寮� @@ -400,13 +409,24 @@ /// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳� /// </summary> /// <param name="port"></param> - public static void Start() + public static bool Start() { - if (udpClient!=null) + if (udpClient != null) { - return; + return true; } - udpClient = new UdpClient { EnableBroadcast = true }; + + //鑾峰彇鎵嬫満鐨剋ifi鍦板潃 + var netwifi = new Shared.Net.NetWiFi(); + string phoneIp = netwifi.GetIPAddress(); + //"127.0.0.1"鏄簳灞傚簱閲岄潰璁剧疆鐨勫垵濮嬮粯璁ゅ�� + if (phoneIp != "127.0.0.1") + { + udpClient = new UdpClient(new IPEndPoint(IPAddress.Parse(phoneIp), 7624)); + udpClient.EnableBroadcast = true; + return true; + } + return false; } /// <summary> @@ -428,12 +448,17 @@ /// 寮傛鍙戦�佹暟鎹� /// </summary> /// <param name="tempPacket"></param> - public static void BeginSend(System.Net.IPEndPoint iPEndPoint, byte[] bytes) + public static void BeginSend(IPEndPoint iPEndPoint, byte[] bytes) { try { - if (udpClient == null) + if (Start() == false) { + //璋冭瘯鐢� + if (Shared.Phone.HdlUserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) + { + Shared.Phone.HdlLogLogic.Current.WriteLog(3, "udp New涓嶈捣鏉�"); + } return; } int value = udpClient.Send(bytes, bytes.Length, iPEndPoint); -- Gitblit v1.8.0