/// <summary> /// 设置基本配置 /// </summary> /// <param name="receiveBufferSize">用于每个套接字I/O操作的缓冲区大小(接收端)</param> /// <param name="ip">ip或者域名</param> /// <param name="port">端口</param> public UdpClient(int receiveBufferSize, string ip, int port) { client = new UdpClients(receiveBufferSize); client.OnReceive += OnReceive; client.OnSend += OnSend; client.Start(ip, port); Console.WriteLine("Udp已启动,端口:" + port); }
static void Main(string[] args) { udpclient = new UdpClients(1024); udpclient.Start("127.0.0.1", 6666); udpclient.OnReceive += UdpServer_OnReceive; udpclient.OnSend += UdpServer_OnSend; for (int i = 0; i < 10; i++) { udpclient.Send(new byte[] { 65, 96 }, 0, 2); } Console.Read(); }
static void Main(string[] args) { udpclient = new UdpClients(1024); udpclient.Start("127.0.0.1", 6666); udpclient.OnReceive += UdpServer_OnReceive; udpclient.OnSend += UdpServer_OnSend; byte[] arg2 = Encoding.UTF8.GetBytes("fdsafdsafdsafdsafdasfdsafffdsafdsafdsafdsafdasfdsaffdsafdsafdsafdsafdasfdsaffdsafaaadsafdsafdsafdasfdsaffdsafdsafdsafdsafdasfdsafdsafdsafdsafdsafdasfdsaffdsafdsafdsafdsafdasfdsaffdsafdsafdsafdsafdasfdsaf"); for (int i = 0; i < int.MaxValue; i++) { udpclient.Send(arg2, 0, arg2.Length); Thread.Sleep(1); } Console.Read(); }
public bool Connect(string ip, int port) { udpClient.Start(ip, port); return(true); }