init csharp server
This commit is contained in:
41
server/src/UdpClientPool.cs
Normal file
41
server/src/UdpClientPool.cs
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user