   [.net] Udp broadcast and receive question (resolved)
  Hello,Basically, I want to broadcast a sort of "here I am" message to an entire subnet whenever my application starts.I have several agents that I want to notify the server on a local network whenever the agent starts on a network. The server will pick up that message and respond back to the agent with all the rest of the relevant information that it needs.  I think that the technology to do this is to use a udp broadcast.  Unfortunately most of my experience is with regular tcp sockets, so I get a little confused when I work with udp.So, I was just wondering if someone on this forum might have a C# code snippet that does a udp broadcast and a code snippet that recieves a broadcast.Thanks,Bradresolved...I used this as a guidehttp://msdn.microsoft.com/en-us/library/tst0kwb1.aspxusing System;using System.Net;using System.Net.Sockets;using System.Text;public class UDPListener{  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;  }}using System;using System.Net;using System.Net.Sockets;using System.Text;class Program{  static void Main(string[] args)  {    Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);    s.EnableBroadcast = true;    System.Net.IPHostEntry address = System.Net.Dns.GetHostByName(Environment.MachineName);    byte[] ba = address.AddressList[0].GetAddressBytes();    string ipaddr = string.Format("{0}.{1}.{2}.255", ba[0], ba[1], ba[2]);    IPAddress broadcast = IPAddress.Parse(ipaddr);   byte[] sendbuf = Encoding.ASCII.GetBytes("Hello");    IPEndPoint ep = new IPEndPoint(broadcast, 11000);    s.SendTo(sendbuf, ep);    Console.WriteLine("Message sent to the broadcast address");  }}[Edited by - BradSnobar on September 8, 2008 12:07:55 PM]