//ConcoleApplication1 //Program.cs- Work as Listnear on port 36502 and listen // from all IP's on LAN using System; using System.Net; using System.Net.Sockets; using System.Text; public class UDPListener { private const int listenPort = 36502; private static void StartListener() { bool done = false; UdpClient listener = new UdpClient(listenPort); listener.Client.EnableBroadcast = true; listener.EnableBroadcast = true; IPEndPoint groupEP = new IPEndPoint(IPAddress.IPv6Any, 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; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)