我正在嘗試創建一個可以接收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**
我真的不知道是什麼問題.....
編輯 - 我改變了端口,並嘗試更改部署雲服務。仍然沒有.... – user2341924