diff --git a/C# UDP Server b/C# UDP Server new file mode 100644 index 0000000..bacc621 --- /dev/null +++ b/C# UDP Server @@ -0,0 +1,50 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Text; + +namespace TestServerUDP +{ + class Program + { + + private const int listenPort = 11000; + + private static void StartListener() + { + bool done = false; + + UdpClient listener = new UdpClient(listenPort); + IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort); + + try + { + while (!done) + { + Console.WriteLine("Waiting for broadcast"); + byte[] bytes = listener.Receive(ref groupEP); + + Console.WriteLine("Received broadcast from {0} :\n {1}\n", + groupEP.ToString(), + Encoding.ASCII.GetString(bytes, 0, bytes.Length)); + } + + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + finally + { + listener.Close(); + } + } + + public static int Main() + { + StartListener(); + + return 0; + } + } +}