【发布时间】:2013-08-02 10:39:32
【问题描述】:
我正在尝试创建一个可以在 TCP 端口上接收消息的天蓝色应用程序。我已经配置了如下所示的输入端点:
端点名称:GPRS端点
类型:输入
协议: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**
我真的不知道问题是什么.....
【问题讨论】:
-
edit- 我更改了端口并尝试更改部署云服务。还是什么都没有……
标签: azure azure-worker-roles tcplistener