static void Main(string[] args) { UDPer udp = new UDPer(); udp.Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, udp.Port); udp.Socket.Bind(localEndPoint); udp.Start(); ConsoleKeyInfo cki; do { if (Console.KeyAvailable) { cki = Console.ReadKey(true); switch (cki.KeyChar) { case 's': udp.Send(new Random().Next().ToString()); break; case 'x': udp.Stop(); return; } } Thread.Sleep(10); } while (true); }
static void Main(string[] args) { UDPer udp = new UDPer(); udp.Start(); ConsoleKeyInfo cki; do { if (Console.KeyAvailable) { cki = Console.ReadKey(true); switch (cki.KeyChar) { case 's': udp.Send(new Random().Next().ToString()); break; case 'x': udp.Stop(); return; } } Thread.Sleep(10); } while (true); }