2013-08-02 38 views
0

我正在嘗試創建一個可以接收TCP端口上的消息的天青應用程序。我已經配置如下圖所示的輸入端點:寫入Azure Worker角色時出錯輸入端點

端點名稱:GPRSEndpoint
類型:輸入
協議:TCP
端口:10000

我蔚藍工作者角色的代碼如下所示: -

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** 

我真的不知道是什麼問題.....

+0

編輯 - 我改變了端口,並嘗試更改部署雲服務。仍然沒有.... – user2341924

回答

0

有一個在http://blog.maartenballiauw.be/post/2010/01/17/Creating-an-external-facing-Azure-Worker-Role-endpoint.aspx一個示例應用程序。你有沒有嘗試過,並比較它在做什麼?

+0

我也有一個天藍色的問題。我已經使用了該示例應用程序 - 最值得注意的是,該示例應用程序中沒有使用或連接到工作者角色。 –

+0

我發現本教程更有幫助。 https://msdn.microsoft.com/en-us/hh285885?f=255&MSPPError=-2147217396 –