From 0f2e0147e8990e913d16d99bc1b94fb6bc53abd7 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期四, 03 十二月 2020 15:35:42 +0800
Subject: [PATCH] 2020-12-03-1

---
 HDL_ON/DAL/DriverLayer/UdpSocket.cs |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
index 4258c9b..f63851c 100644
--- a/HDL_ON/DAL/DriverLayer/UdpSocket.cs
+++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -21,22 +21,32 @@
 
 		//鏈湴Socket
 		private Socket busSocket;
-
+		int _port = 0;
 		/// <summary>
 		/// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳�
 		/// </summary>
-		public void Start ()
+		public void Start (int port)
         {
-            if (IsRunning ) {
-                return;
+			if (IsRunning)
+			{
+                if (port == _port)
+                {
+                    return;
+                }
+                else
+                {
+                    busSocket.Close();
+                }
             }
+            _port = port;
 
             busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             busSocket.EnableBroadcast = true;
             try {
-                busSocket.Bind (new IPEndPoint (IPAddress.Any, 6000));
+                //busSocket.Bind (new IPEndPoint (IPAddress.Any, 6000));
+                busSocket.Bind(new IPEndPoint(IPAddress.Any, port));
 
-				busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
+                busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
 			}
 			catch{
                 busSocket = null;
@@ -45,7 +55,7 @@
 
             asyncBeginReceive();
 
-            MainPage.Log ($"udp port : 6000");
+            MainPage.Log ($"udp port : {port}");
         }
 
 		/// <summary>
@@ -119,10 +129,11 @@
 				packet.Bytes = new byte[len];
 				Array.Copy(bytes, 0, packet.Bytes, 0, packet.Bytes.Length);
 
+				//MainPage.Log($"鎺ユ敹{packet.RemoteEndPoint}鏁版嵁");
 				//mqtt杩炴帴鏁版嵁璇诲彇  A鍗忚缃戠粶璁惧淇℃伅璇诲彇鍥炲 澶勭悊
 				if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585)
 				{
-					DriverLayer.A_Protocal_Common.apc.ConvertReceiveData(bytes);
+					Control.Ins.ConvertReceiveData(bytes);
 				}
 				else if(((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//澶勭悊bus 6000绔彛鐨勬暟鎹�
 				{

--
Gitblit v1.8.0