24

I am looking to build an application in Azure which will act as TCP listener, receive TCP message streams on a specified port, and then add the information to a database. The incoming TCP communication will be secured with a certificate.

I'm considering the following options:

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.

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.

However I'm not sure this approach will work, and I have the following questions:

  • Can I expose arbitrary TCP ports on the App Service?
    • Whilst the Cloud Service documentation specifically describes how to do this, I can't find anything similar for the App Service. So, either the configuration is not required or TCP communication is just not possible within the App Service.
  • Can I build a TCP listener inside an Logic App, API App, or Web Job, e.g. does the architecture of Azure support the behaviour required for a TCP listener?

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

James Wood
  • 17,286
  • 4
  • 46
  • 89
  • Can you make this work over HTTP? All these concerns just go away. – usr Jul 12 '16 at 15:57
  • Sadly no, TCP is a requirement of the application at the other end. – James Wood Jul 12 '16 at 16:03
  • Then be advised that MSDN TCP tutorials are really bad. In particular https://msdn.microsoft.com/en-us/library/fx6588te(v=vs.110).aspx is horrible. Also writing socket code is hard. If you cannot recognize that this tutorial is bad this means that you are quite inexperienced and will have an even harder time. Just warning you. – usr Jul 12 '16 at 16:04
  • 1
    Regardless of the code quality in that example, the important bit is that's its something that can be done. More interested in the hosting at the moment. – James Wood Jul 12 '16 at 16:09
  • This question is off-topic, as it's too broad: Nothing stops you from running a tcp listener in many different services, such as VM's, cloud services, an dWeb Apps. Each has its own specific set of advantages, and which you choose for your server-side code is really up to you and your app's needs. Also, you're asking a mixture of yes/no questions and opinion-soliciting questions. – David Makogon Jul 12 '16 at 20:38
  • 2
    @DavidMakogon, does that mean all this stuff is possible then? For example; Cloud Service documentation specifically describes how to open a TCP port, whilst I can't find anything similar for App Services. This either means the same configuration is not required, or the TCP listener is not a possible configuration for App Services. I have reworded to narrow down the scope of the question, to what I believe are just yes/no answers. – James Wood Jul 12 '16 at 21:20

2 Answers2

11

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.

Definitely works.

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

In 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?

No and No. Only 80/TCP and 443/TCP are exposed publicly and the only protocol that works is HTTP. You can't do custom listeners with App Service.

See the sandbox limitations listed here: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#network-endpoint-listening

Feel free to make a pull request in the Azure documentation if this limitation is not mentioned on the App Service page.

Service Fabric would be a cool 3rd (or 1st?) option: https://azure.microsoft.com/en-us/services/service-fabric/

evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • 1
    What does this mean for WebSockets? I'm assuming that it is supported for WebJobs. – jpierson Aug 31 '16 at 18:10
  • @jpierson, WebSockets are an upgrade from HTTP, so this does not restrict them. I believe they should work in web jobs, but not logic and function apps that have restrictions on long running tasks. – Jan Hudec Aug 09 '23 at 07:46
7

I raised a support ticket and confirmed this with 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.

Also further collaborating information this question; Can I open ports on Azure Websites?

Community
  • 1
  • 1
James Wood
  • 17,286
  • 4
  • 46
  • 89