try to fix bug

This commit is contained in:
2025-04-15 21:38:06 +08:00
parent e8ec4c2a86
commit 84699708d5
3 changed files with 71 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
class UDPClientPool
public class UDPClientPool
{
private static IPAddress localhost = IPAddress.Parse("127.0.0.1");
@@ -13,6 +13,8 @@ class UDPClientPool
byte[] sendbuf = Encoding.ASCII.GetBytes(stringArray[0]);
var sendLen = socket.SendTo(sendbuf, endPoint);
socket.Close();
if (sendLen == stringArray[0].Length) { return true; }
else { return false; }
}
@@ -26,6 +28,8 @@ class UDPClientPool
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var sendLen = socket.SendTo(buf, endPoint);
socket.Close();
if (sendLen == buf.Length) { return true; }
else { return false; }
}
@@ -40,6 +44,8 @@ class UDPClientPool
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var sendBytes = pkg.ToBytes();
var sendLen = socket.SendTo(sendBytes, endPoint);
socket.Close();
if (sendLen == sendBytes.Length) { return true; }
else { return false; }
}
@@ -54,6 +60,8 @@ class UDPClientPool
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
var sendBytes = pkg.ToBytes();
var sendLen = socket.SendTo(sendBytes, endPoint);
socket.Close();
if (sendLen == sendBytes.Length) { return true; }
else { return false; }
}
@@ -71,6 +79,8 @@ class UDPClientPool
IPEndPoint ep = new IPEndPoint(localhost, port);
var sendLen = socket.SendTo(sendBytes, ep);
socket.Close();
if (sendLen == sendBytes.Length) { return true; }
else { return false; }
}
@@ -87,5 +97,7 @@ class UDPClientPool
Thread.Sleep(sleepMilliSeconds);
}
socket.Close();
}
}

View File

@@ -92,7 +92,7 @@ public class UDPServer
{
Console.WriteLine(e.ToString());
throw new ArgumentException(
$"Not currect port num: {port}",
$"Failed to set up server with this port: {port}",
nameof(port)
);
}
@@ -143,7 +143,7 @@ public class UDPServer
}
else
{
return Optional.Some((UDPData)data);
return Optional.Some((UDPData)data.DeepClone());
}
}
@@ -196,7 +196,7 @@ public class UDPServer
}
else
{
return Optional.Some((UDPData)data);
return Optional.Some((UDPData)data.DeepClone());
}
}