From b7638936d350eb1f48c02895b9275c79587726ce Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 15 十二月 2020 17:18:48 +0800
Subject: [PATCH] 2020-12-15-3
---
HDL_ON/DAL/DriverLayer/UdpSocket.cs | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
index 39b3dfd..3ffb628 100644
--- a/HDL_ON/DAL/DriverLayer/UdpSocket.cs
+++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -21,22 +21,35 @@
//鏈湴Socket
private Socket busSocket;
-
+ int _port = 0;
/// <summary>
/// 鍚姩Socket鎺ユ敹鍜屽彂閫佸姛鑳�
/// </summary>
- public void Start (int port)
+ public void Start (int port = 0)
{
- if (IsRunning ) {
- return;
+ if (IsRunning)
+ {
+ if (port == _port)
+ {
+ return;
+ }
+ else
+ {
+ busSocket.Close();
+ }
}
+ if (port != 0)
+ _port = port;
+ if (_port == 0)
+ return;
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;
@@ -119,7 +132,7 @@
packet.Bytes = new byte[len];
Array.Copy(bytes, 0, packet.Bytes, 0, packet.Bytes.Length);
- MainPage.Log($"鎺ユ敹IP{packet.RemoteEndPoint}鏁版嵁");
+ //MainPage.Log($"鎺ユ敹{packet.RemoteEndPoint}鏁版嵁");
//mqtt杩炴帴鏁版嵁璇诲彇 A鍗忚缃戠粶璁惧淇℃伅璇诲彇鍥炲 澶勭悊
if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585)
{
--
Gitblit v1.8.0