首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自Azure函数的TcpIp通信?

来自Azure函数的TcpIp通信?
EN

Stack Overflow用户
提问于 2018-03-29 23:33:41
回答 1查看 492关注 0票数 1

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

代码语言:javascript
复制
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:这仍然不起作用,我已经尝试以以下方式生成客户机:

代码语言:javascript
复制
// 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”之外,所有这些方法都能正常工作。在服务器上,我得到以下错误:

代码语言:javascript
复制
== 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
EN

回答 1

Stack Overflow用户

发布于 2018-03-30 06:00:01

看看您的TcpClient实例,

var client =新的TcpClient(AddressFamily.InterNetworkV6)

Azure函数中还没有IPv6。将您的AddressFamily切换到v4:

代码语言:javascript
复制
var client = new TcpClient(AddressFamily.InterNetwork)

在App /Functions中,对出站取消没有限制。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49566498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档