写入Azure辅助角色输入端点时出错

时间:2013-08-02 10:39:33

标签: azure azure-worker-roles tcplistener

我正在尝试创建一个可以在TCP端口上接收消息的azure应用程序。我已经配置了如下所示的输入端点:

端点名称:GPRSEndpoint
类型:输入
协议:TCP
端口:10000

我的azure worker角色代码如下所示: -

TcpListener listener = new TcpListener(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["GPRSEndpoint"].IPEndpoint);
        listener.ExclusiveAddressUse = false;
        listener.Start();

 while (true)
            {
                Thread.Sleep(100);
                if (listener.Pending())
                {
                    Trace.WriteLine("Incoming Request", "Information");
                    TcpClient c = listener.AcceptTcpClient();  //waiting for client to connect
                    Stream s = c.GetStream();
                    StreamReader sr = new StreamReader(s);
                    string text = sr.ReadLine();

                    if (text != null && text.Length > 0)
                    {
                        Trace.WriteLine("Saving GPRS Packets into Storage Table", "Information");
                        //Saving GPRS Packets into Storage Table
                        Site site = new Site();
                        site.GPRSPacket = text;
                        var insertOperation = TableOperation.Insert(site);
                        siteTable.Execute(insertOperation);
                    }
                    c.Close();
               }

               Trace.TraceInformation("Working", "Information");
            }
        }

最后我的客户端程序如下所示: -

TcpClient c = new TcpClient();
            Console.WriteLine("\nConnecting to Azure...");

            IPAddress AzureWorkeraddress = IPAddress.Parse("168.63.239.54");
            //String AzureWorkeraddress = "http://clienttcpcloud.cloudapp.net/";
            //IPAddress AzureWorkeraddress = IPAddress.Parse("65.52.184.129");

            c.Connect(AzureWorkeraddress, 10000);  //Azure Worker Role's INPUT TCP Endpoint 168.63.239.54 or (http://clienttcpcloud.cloudapp.net/)
            Console.WriteLine("\n<<<<<<<<<<<<<<<<<<Server Connected>>>>>>>>>>>>>>>>>>\n");

            Console.WriteLine("Sending to Azure...");
            Stream s = c.GetStream();
            StreamWriter sw = new StreamWriter(s);
            sw.WriteLine(text);
            sw.Flush();
            Console.WriteLine("\n\nGPRS Packet Sent!!!");

            s.Close();
            c.Close();

我尝试将端口号更改为多个值,但仍无法响应。我得到的错误是: -

**A Connection failed because the connecting party did not properly respond after a period of time, or the established connection failed, because connected host failed to respond 168.63.239.54:10000**

我真的不知道问题是什么.....

1 个答案:

答案 0 :(得分:0)

http://blog.maartenballiauw.be/post/2010/01/17/Creating-an-external-facing-Azure-Worker-Role-endpoint.aspx有一个示例应用程序。你有没有尝试过,并将它正在做的事情与你正在做的事情进行比较?