azure - 来自 Azure Function 的 TcpIp 通信?

标签 azure azure-functions tcpclient

我有一个 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);
   }
}

我返回的错误:

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

端点地址看起来正确,并且当我在本地调试时此代码可以工作,因此我怀疑 azure 服务器可能不允许出站连接。

知道为什么此连接不起作用吗?

<小时/>

更新:这仍然不起作用,我尝试通过以下方式生成客户端:

// 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

最佳答案

查看您的 TcpClient 实例,

var client = new TcpClient(AddressFamily.InterNetworkV6)

Azure Functions 中尚无 IPv6。将您的 AddressFamily 切换到 v4:

var client = new TcpClient(AddressFamily.InterNetwork)

应用服务/功能中的出站目的地没有限制。

关于azure - 来自 Azure Function 的 TcpIp 通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49566498/

相关文章:

Azure 孤立存储帐户

sql - 将数据从 Azure 数据库保存到 Windows 8 应用程序并从中读取数据

azure - 每个国家/地区架构的数据库

Azure Functions Docker 部署 Linux 工作线程在资源组中不可用

Android Java TCP 客户端服务器文件传输

Azure 逻辑应用程序 - 可以创建此自定义 RBAC 规则吗?

python - 如何使用python从azure函数应用程序的请求中读取cookie

c# - 无法连续发送三个或更多数据包

c# - TcpClient 超时与 NetworkStream 超时

azure - 如何限制azure中预算的使用