title: I cannot make UDP Ports work on a Windows Azure Virtual Machine
body: <p>I cannot receive a UDP packet on a Windows Azure Virtual Machine. I have done the following:</p>
  
  <ol>
  <li><p>On the Virtual Machine, via Windows Firewall, I opened up Port 1234* both Inbound and Outbound for both UDP and TCP protocols. I did not add any IP exclusions. The rule should apply to Domain, Private and Public profiles. I am allowing Block Edge Traversal.</p></li>
  <li><p>In the Azure Management Portal, I added Endpoints for my Virtual Machine instance. I added both UDP and TCP protocol endpoints. Public and Private port numbers are both 1234.</p></li>
  </ol>
  
  <p>I have two test programs that I wrote: UDPSender and UDPReceiver. Using two computers on my local network, the test programs successfully sent a packet between them. (Edit: I also used <a href="https://play.google.com/store/apps/details?id=com.synprez.udp_tester" rel="nofollow">UDPTester Android App</a> to successfully send a 'trans-ISP' message to my PC running the UDPReceiver.)</p>
  
  <p>Moving UDPReceiver to my Virtual Machine, I cannot successfully receive a message.</p>
  
  <p>Did I miss anything in my Azure Endpoint configuration? Please Help!</p>
  
  <p><code>*</code> Port Number changed to protect the innocent.</p>
  
  <hr>
  
  <p>Test Program Code Below...</p>
  
  <hr>
  
  <p><strong>UDPSender:</strong></p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          textMessage.Text = "Knock, knock";
          textIP.Text = "xxx.xxx.xxx.xxx";
          textPort.Text = "1234";
      }
  
      private void buttonSend_Click(object sender, EventArgs e)
      {
          UdpClient udpClient = new UdpClient(textIP.Text, Convert.ToInt32(textPort.Text));
          Byte[] sendBytes = Encoding.ASCII.GetBytes(textMessage.Text);
          try
          {
              udpClient.Send(sendBytes, sendBytes.Length);
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
      }
  }
  </code></pre>
  
  <p><strong>UDPReceiver:</strong></p>
  
  <pre><code>private static void Main(string[] args)
      {
          //Creates a UdpClient for reading incoming data.
          UdpClient receivingUdpClient = new UdpClient(1234);
          while (true)
          {
              //Creates an IPEndPoint to record the IP Address and port number of the sender.
              // The IPEndPoint will allow you to read datagrams sent from any source.
              System.Net.IPEndPoint RemoteIpEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
              try
              {
  
                  // Blocks until a message returns on this socket from a remote host.
                  Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
  
                  string returnData = Encoding.ASCII.GetString(receiveBytes);
  
                  string messageOut = String.Format("[{0},{1}]@[{2}]: {3}",
                      RemoteIpEndPoint.Address.ToString(),
                      RemoteIpEndPoint.Port.ToString(),
                      DateTime.Now,
                      returnData.ToString());
  
                  Console.WriteLine(messageOut);
              }
              catch (Exception ex)
              {
                  Console.WriteLine(ex.ToString());
              }
          }
      }
  </code></pre>