title: UDPClient messages not receiving
body: <p>I am semi-new to C#, VS, and .NET. I have some basics down, however I am having a really hard time communicating with UDP with a servo controller that I have.</p>
  
  <p>I am hoping someone can guide me on what is wrong with my code, how this works, and what is the best approach for receiving messages.</p>
  
  <p>My first step is to broadcast a "who" message and when my servo sees this, I will get a response back with information about about that servo.</p>
  
  <pre><code>public void Discover()
          {
              byte[] message = Encoding.ASCII.GetBytes("who");
              IPEndPoint targetEndPoint = new IPEndPoint(IPAddress.Broadcast, LINKPORT);
              IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
  
              System.Console.WriteLine("New Transimission Sequence:");
              foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
              {
                  if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                  {
                      foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
                      {
                          if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                          {
                              IPEndPoint localEndpoint = new IPEndPoint(IPAddress.Parse(ip.Address.ToString()), LINKPORT);
  
                              UdpClient udpClient = new UdpClient(localEndpoint);
                              udpClient.Send(message, message.Length, targetEndPoint);
  
                              UdpClient udpClientB = new UdpClient(remoteEndPoint);
                              udpClientB.Client.ReceiveTimeout = 1000;
                              string recvMessage;
                              try
                              {
                                  recvMessage = System.Text.Encoding.UTF8.GetString(udpClientB.Receive(ref remoteEndPoint));
                              }
                              catch (Exception e)
                              {
                                  recvMessage = e.Message;
                              }
  
                              System.Console.WriteLine(recvMessage);
  
                              udpClient.Close();
                              udpClientB.Close();
                          }
                      }
                  }
              }
  
              System.Console.WriteLine("==========================================================================================");
  
              return;
          }
  </code></pre>
  
  <p>This is what I currently have. I understand it is very crude at the moment, however I can't even get this to work... I am attempting to broadcast a 'who' message across all of my network cards in the code above. And then using <code>udpClientB</code>, I want to receive the message. I have tried using the <code>udpClient</code> and that didn't work, and that's why I created <code>udpClientB</code>. I have also tried creating a separate thread that just listens on that port and nothing...</p>
  
  <p>Right now this is what I am getting on my console window.</p>
  
  <pre><code>New Transimission Sequence:
  Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  ==========================================================================================
  </code></pre>
  
  <p>When I tried using <code>udpClient</code> as the sender and receiver, I was getting "who" in my console window... What am I doing wrong? What is going on?</p>
  
  <p>I tripled check and the messages are being sent and I am responding to the message when it reaches my servo controller, that is happening.</p>
  
  <p>Also a question for after this is done, what is the best approach for this kind of stuff? This code is getting hit by a windows form button, eventually I want to display everyone who responded on a windows form list. Should I create asynchronous function calls? Use a 'Timer' to constantly listen and empty the ethernet buffer? Create a new thread to listen? Or what I am currently doing, just in-line?</p>
  
  <p>Thank you for your time in reading this.</p>