我无法使UDP端口在Windows Azure虚拟机上工作 [英] I cannot make UDP Ports work on a Windows Azure Virtual Machine

查看:56
本文介绍了我无法使UDP端口在Windows Azure虚拟机上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Windows Azure虚拟机上收到UDP数据包.我已完成以下操作:

I cannot receive a UDP packet on a Windows Azure Virtual Machine. I have done the following:

  1. 在虚拟机上,通过Windows防火墙,我为UDP和TCP协议打开了入站和出站的端口1234 *.我没有添加任何IP排除项.该规则应适用于域,专用和公用配置文件.我允许块边缘遍历.

  1. 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.

在Azure管理门户中,我为虚拟机实例添加了端点.我同时添加了UDP和TCP协议端点.公共和专用端口号均为1234.

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.

我编写了两个测试程序:UDPSender和UDPReceiver.使用本地网络上的两台计算机,测试程序成功地在它们之间发送了一个数据包.(我还使用了 UDPTester Android应用成功向运行UDPReceiver的PC发送"trans-ISP"消息.)

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. ( I also used UDPTester Android App to successfully send a 'trans-ISP' message to my PC running the UDPReceiver.)

将UDPReceiver移至我的虚拟机时,我无法成功接收消息.

Moving UDPReceiver to my Virtual Machine, I cannot successfully receive a message.

我没有在Azure端点配置中错过任何内容吗?请帮忙!

Did I miss anything in my Azure Endpoint configuration? Please Help!

* 端口号已更改,以保护无辜者.

* Port Number changed to protect the innocent.

下面的测试程序代码...

Test Program Code Below...

UDPSender:

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());
        }
    }
}

UDPReceiver:

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());
            }
        }
    }

推荐答案

代码看起来正确.我将其与我的实现进行了比较.以下是供参考的关键部分:

The code looks correct. I compared it against my implementation. Here are the key sections for reference:

您的csdef应该具有正确的端口协议.您说您是通过门户网站完成的,但是请确认保存的设置:

Your csdef should have the correct port protocol. You said you did this through the portal, but confirm the settings saved:

<Endpoints>
    <InputEndpoint name="UdpEndpoint" protocol="udp" port="8080" localPort="8080" />
</Endpoints>

(来自 https://github.com/ytechie/LogHub/blob/master/Microsoft.LogHub.Cloud/ServiceDefinition.csdef )

在正确的端口上侦听就像:

And listening on the correct port was as easy as:

var endPoint = new IPEndPoint(IPAddress.Any, 0);
var udp = new UdpClient(8080);

(来自 https://github.com/ytechie/LogHub/blob/master/Microsoft.LogHub/Global.asax.cs )

随时查看我的实现并寻找差异.我确实注意到您正在使用接收"的同步版本,但这没关系.

Feel free to take a look at my implementation and look for differences. I did notice that you're using the synchronous version of "Receive", but that shouldn't matter.

我也很好奇这是PaaS还是IaaS.无论哪种情况,您都需要触及负载平衡端点,而不是无法从Internet访问的内部端点.

I'm also curious if this is PaaS or IaaS. In either case, you'll need to hit against the load balanced endpoint, and not an internal endpoint which would be inaccessible from the internet.

这篇关于我无法使UDP端口在Windows Azure虚拟机上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆