我有一个azure队列触发器函数,它具有以下代码:
using (var client = new TcpClient(AddressFamily.InterNetworkV6))
{
client.Client.DualMode = true;
client.Connect(endpoint);
var data = Encoding.ASCII.GetBytes("test");
using (var outStream = client.GetStream())
{
outStream.Write(data, 0, data.Length);
}
}我得到的错误是:
连接尝试失败是因为连接方在一段时间后没有正确响应,或者已建立的连接失败是因为连接主机未能响应。
端点地址看起来是正确的,当我在本地调试时,此代码可以工作,因此我怀疑azure服务器可能不允许出站连接。
你知不知道为何这种联系不起作用?
Update:这仍然不起作用,我已经尝试以以下方式生成客户机:
// DualMode IPV6
var client = new TcpClient(AddressFamily.InterNetworkV6);
client.Client.DualMode = true;
client.Connect(endpoint);
// SingleMode Internetwork
var client = new TcpClient(AddressFamily.InterNetwork);
client.Connect(endpoint);
// Just Endpoint
var client = new TcpClient(endpoint);
client.Connect(endpoint);
// Normal
var client = new TcpClient(hostAddress, port);
// Forced IPV6
var client = new TcpClient("::ffff:" + hostAddress, port);在本地调试时,除了“强制IPV6”之外,所有这些方法都能正常工作。在服务器上,我得到以下错误:
== DualMode IPV6
Failed PingBack: A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host
has failed to respond [::ffff:204.16.184.62]:3164
== SingleMode Internetwork
Failed PingBack: A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host
has failed to respond 204.16.184.62:3164
== Just Endpoint
Failed PingBack: The requested address is not valid in its context
== Normal
Failed PingBack: A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host
has failed to respond 204.16.184.62:3164
== Forced IPV6
Failed PingBack: The requested address is not valid in its context [::ffff:204.16.184.62]:3164发布于 2018-03-30 06:00:01
看看您的TcpClient实例,
var client =新的TcpClient(AddressFamily.InterNetworkV6)
Azure函数中还没有IPv6。将您的AddressFamily切换到v4:
var client = new TcpClient(AddressFamily.InterNetwork)在App /Functions中,对出站取消没有限制。
https://stackoverflow.com/questions/49566498
复制相似问题