init csharp server

This commit is contained in:
2025-03-29 19:02:18 +08:00
parent cddf92e432
commit 351aad8300
12 changed files with 216 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
class UDPClientPool
{
private static IPAddress localhost = IPAddress.Parse("127.0.0.1");
public UDPClientPool()
{
}
public static void SendLocalHost(int port, string[] stringArray)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
byte[] sendbuf = Encoding.ASCII.GetBytes(stringArray[0]);
IPEndPoint ep = new IPEndPoint(localhost, port);
socket.SendTo(sendbuf, ep);
}
public static void CycleSendLocalHost(int times, int sleepMilliSeconds, int port, string[] stringArray)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
byte[] sendbuf = Encoding.ASCII.GetBytes(stringArray[0]);
IPEndPoint ep = new IPEndPoint(localhost, port);
while (times-- >= 0)
{
socket.SendTo(sendbuf, ep);
Thread.Sleep(sleepMilliSeconds);
}
}
public void Start()
{
}
}