title: UDP broadcasts are not being received by sender
body: <p>Platform: Windows 2003 R2, C#</p>
  
  <p>I have an application that sends UDP messages to other instances of itself, running on the same computer and on other computers.  This is working fine.  But, on some computers, the listener cannot hear messages that other thread/process on the same computer has transmitted.  The message is broadcast ok, and other machines on the network hear the message, but a listener on the same machine cannot hear the message.</p>
  
  <p>The weird part is that this happens on SOME machines in my test environment, but not all.</p>
  
  <p><strong>Edit:  All machine that fail have the Check Point VPN-1 Securemote client software installed.  I took a machine that was working, installed the VPN client, and now it does not work.  Note that I am not connected to any VPN hosts, I just have the client installed.</strong></p>
  
  <p>All machines have a single network adapter, subnet mask of 255.255.255.0, and IP address of 10.3.10.xxx.</p>
  
  <p>Here is a test class that demonstrates the problem.  The user types some text, and it gets sent to 10.3.10.255.  On some machines, the ReceiveFrom returns, and on others it does not.  I am calling Controller("10.3.10.255",33333)</p>
  
  <pre><code>public class Controller
  {
      public Controller(IPAddress broadcastAddress, int port)
      {
           _broadcastAddress = broadcastAddress;
           _port = port;
      }
  
      public void Start()
      {
          Socket s = null;
  
          try
          {
               IPEndPoint _listenEndpoint = new IPEndPoint(IPAddress.Any, _port);
              _broadcastEndpoint = new IPEndPoint(_broadcastAddress, _port);
  
              s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
              s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10);
              s.EnableBroadcast = true;
              s.Bind(_listenEndpoint);
  
              SocketState receiveState = new SocketState();
              receiveState.s = s;
              receiveState.buf = new byte[1024];
  
              EndPoint lep = (EndPoint)_broadcastEndpoint;
  
              s.BeginReceiveFrom(receiveState.buf, 0, receiveState.buf.Length, SocketFlags.None, ref lep, new AsyncCallback(OnReceive), receiveState);
  
              bool done = false;
              while (!done)
              {
                  string msg = Console.In.ReadLine();
                  byte[] msg_bytes = Encoding.ASCII.GetBytes(msg);
  
                  if (msg_bytes.Length == 0)
                      done = true;
                  else
                  {
                      Console.Out.WriteLine("---&gt; {0}", msg);
                      s.SendTo(msg_bytes, msg_bytes.Length, SocketFlags.None, new IPEndPoint(_broadcastAddress, _port));
                  }
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
          finally
          {
              if (s != null)
                  s.Close();
          }
      }
  
      internal void OnReceive(IAsyncResult ar)
      {
          SocketState state = ar.AsyncState as SocketState;
          IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 0);
          EndPoint ep = (EndPoint)ipep;
  
          int nRead = state.s.EndReceiveFrom(ar, ref ep);
  
          IPEndPoint myipep = ep as IPEndPoint;
  
          Console.WriteLine("&lt;--- {0} {1}", myipep.Address.ToString(), System.Text.Encoding.ASCII.GetString(state.buf, 0, nRead));
  
          EndPoint lep = (EndPoint)_broadcastEndpoint;
          state.s.BeginReceiveFrom(state.buf, 0, state.buf.Length, SocketFlags.None, ref lep, new AsyncCallback(OnReceive), state);
      }
  
      IPAddress _broadcastAddress;
      int _port = 0;
      IPEndPoint _broadcastEndpoint;
  }
  
  internal class SocketState
  {
      internal Socket s;
      internal byte[] buf;
  }
  </code></pre>