如何在 Azure 中托管 TCP 侦听器?

How can I host a TCP Listener in Azure?

我希望在 Azure 中构建一个应用程序,它将充当 TCP 侦听器,在指定端口上接收 TCP 消息流,然后将信息添加到数据库中。传入的 TCP 通信将使用证书进行保护。

我正在考虑以下选项:

云服务工作者角色

这个看起来肯定会work. However that means I have to use a Cloud Service, and I miss out on the features and simplicity offered by the App Service. The Cloud Service documentation还具体描述了如何打开需要的TCP端口

应用服务

在逻辑应用程序中(首选),但这似乎本身不支持 TCP 侦听器,因此我希望构建自定义 API 应用程序。或者我可以创建一个 Web 作业。

但是我不确定这种方法是否有效,我有以下问题:

我可以在 Azure 应用服务中托管 TCP 侦听器吗?

Cloud Service Worker Role

This definitely looks like it will work. However that means I have to use a Cloud Service, and I miss out on the features and simplicity offered by the App Service. The Cloud Service documentation also specifically describes how to open the required TCP ports.

绝对有效。

https://msdn.microsoft.com/en-us/library/azure/gg557553.aspx

ServiceDefinition.csdef:

<Endpoints>
  <InputEndpoint name="RawTCP" protocol="tcp" port="54321" localPort="54321" />
</Endpoints> 

App Service

In a Logic App (preferred), however this doesn't seem to natively support a TCP >listener, so I would look to build a custom API App. Alternatively I could create a Web Job. ...

Can I expose arbitrary TCP ports on the App Service? ...

Can I host a TCP Listener in an Azure App Service?

不,不。只有 80/TCP 和 443/TCP 被公开,唯一有效的协议是 HTTP。 您不能使用应用服务进行自定义侦听器。

查看此处列出的沙盒限制: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#network-endpoint-listening

如果应用服务页面上未提及此限制,请随时在 Azure 文档中提出拉取请求。

Service Fabric 将是很酷的第三(或第一?)选项: https://azure.microsoft.com/en-us/services/service-fabric/

我提出了支持请求并与 Microsoft 确认了这一点。

[In the App Service] Azure doesn’t support customized port and only support http protocol. These 2 reasons deny the use of TCP listener.

还进一步合作了这个问题的信息; Can I open ports on Azure Websites?