From 86325cf53601d57fff61b6bf77da9c7d341a9327 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期四, 24 八月 2023 18:15:11 +0800
Subject: [PATCH] 2023年08月24日18:14:58
---
HDL_ON/DAL/DriverLayer/UdpSocket.cs | 32 ++++++++++++++++++++++++++------
1 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/HDL_ON/DAL/DriverLayer/UdpSocket.cs b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
index f454bf1..df9662a 100644
--- a/HDL_ON/DAL/DriverLayer/UdpSocket.cs
+++ b/HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -29,14 +29,14 @@
{
if (IsRunning)
{
- if (port == Port)
+ if (port == Port)
{
return;
- }
+ }
else
{
busSocket.Close();
- }
+ }
}
if (port != 0)
Port = port;
@@ -49,6 +49,7 @@
busSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
+ relinkCount = 0;
}
catch (Exception ex){
MainPage.Log ($"udp port bind error : {ex.Message}");
@@ -67,6 +68,10 @@
/// </summary>
public void Stop()
{
+ if(busSocket == null)
+ {
+ return;
+ }
if (!IsRunning)
{
return;
@@ -74,10 +79,11 @@
try
{
busSocket.Close();
+ relinkCount = 0;
}
catch { }
busSocket = null;
- MainPage.Log("Socket鍏抽棴");
+ MainPage.Log("Socket鍏抽棴");
}
/// <summary>
@@ -100,6 +106,10 @@
{
return;
}
+ if(busSocket == null)
+ {
+ return;
+ }
try {
Packet packet = new Packet ();
@@ -107,10 +117,21 @@
}
catch (Exception e) {
System.Threading.Thread.Sleep (1);
- asyncBeginReceive ();
+ Console.WriteLine("asyncBeginReceive " + relinkCount );
+ if (relinkCount == 0)
+ {
+ relinkCount = 1;
+ asyncBeginReceive();
+ }
Console.WriteLine($"asyncBeginReceive {e.Message}");
}
}
+ /// <summary>
+ /// 閲嶈繛娆℃暟
+ /// </summary>
+ private int relinkCount = 0;
+
+
/// <summary>
/// 寮傛鎺ユ敹鏁版嵁缁撴潫
@@ -140,7 +161,6 @@
//mqtt杩炴帴鏁版嵁璇诲彇 A鍗忚缃戠粶璁惧淇℃伅璇诲彇鍥炲 澶勭悊
if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585)
{
- MainPage.Log($"灞�鍩熺綉udp淇℃伅");
Control.Ins.ConvertReceiveData(bytes, ((IPEndPoint)packet.RemoteEndPoint).Address.ToString());
}
else if (((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//澶勭悊bus 6000绔彛鐨勬暟鎹�
--
Gitblit v1.8.0