如何连接到与TCP端点的Azure工作者角色? TCP和Azure的技术需要帮助 [英] How do I connect to a Azure Worker Role with tcp endpoint? Tech help needed with Tcp and Azure
问题描述
我创建了Visual Studio中的辅助角色,并部署到Azure上。 Azure的显示它在我的分期运行。
I created a worker role in visual studio and deployed it to Azure. Azure shows it is running on my staging.
在我的云服务的屏幕没有为服务URL,但是这似乎并没有做任何事情,当我ping到它,或只是导航那里。我得到:
On my cloud services screen there is a URL for the service, but that doesn't seem to do anything when I ping it or just navigate there. I get:
这网页无法使用
ERR_NAME_NOT_RESOLVED
ERR_NAME_NOT_RESOLVED
我写了下面的代码,试图通过TcpClient的访问服务:
I wrote the following code to try and access the service through a TcpClient:
string ip = "http://mysite.cloudapp.net";
int port = 10;
TcpClient client = new TcpClient();
try
{
client.Connect(ip, port); // This line throws the error.
if (client.Connected)
{
client.Close();
}
}
catch (Exception ex)
{
Trace.Warn(ex.Message);
}
在client.Connect(IP,端口)存在,上面写着$错误b $ b 消息=请求的名称是有效的,但没有请求的类型的数据中发现
On client.Connect(ip, port) There is an error that says Message = "The requested name is valid, but no data of the requested type was found"
我WorkerRole具有以下运行方法(从网上教程中,我认为复制)。
My WorkerRole has the following Run method (copied from an online tutorial i believe).
public override void Run()
{
Trace.TraceInformation("wr is running");
TcpListener listener = null;
try
{
listener = new TcpListener(
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["myEndpoint"].IPEndpoint);
listener.ExclusiveAddressUse = false;
listener.Start();
}
catch (SocketException)
{
Trace.Write("Echo server could not start.", "Error");
return;
}
while (true)
{
IAsyncResult result = listener.BeginAcceptTcpClient(HandleAsyncConnection, listener);
connectionWaitHandle.WaitOne();
}
}
最后,在我的csdef我的终点会出现像这样:
Finally in my csdef my endpoint appears like so:
<InputEndpoint name="myEndpoint" protocol="tcp" port="10" localPort="10" />
我想获得说话来回连接。
I'd like to get the connection talking back and forth.
推荐答案
我以为我可以使用的网址,但显然用我的服务页面上蔚蓝色的门户网站列出的ip地址,在输入端点(一种明显) 。我做了以下内容:
I thought that I could use the url, but apparently using the ipaddress listed on the azure portal on my service page, under the Input Endpoints (kind of obvious). I did the following:
IPAddress ipAddress = IPAddress.Parse("13.71.112.31");
int port = 10;
TcpClient client = new TcpClient();
try
{
client.Connect(ipAddress, port);
if (client.Connected) // now true
{
我用这教程作为参考。
这篇关于如何连接到与TCP端点的Azure工作者角色? TCP和Azure的技术需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!