首页 文章

来自Azure功能的TcpIp通信?

提问于
浏览
0

我有一个azure Queue触发器函数,它具有以下代码:

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);
   }
}

我得到的错误:

连接尝试失败,因为连接方在一段时间后没有正确响应,或者 Build 的连接失败,因为连接的主机无法响应

endpoints 地址看起来正确,当我在本地调试时此代码有效,因此我怀疑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

1 回答

  • 2

    看着你的 TcpClient 实例,

    var client = new TcpClient(AddressFamily.InterNetworkV6)

    Azure功能中还没有IPv6 . 将 AddressFamily 切换到v4:

    var client = new TcpClient(AddressFamily.InterNetwork)
    

    App Service / Functions中的出站设置没有限制 .

相关问题