Azure + Socket.IO for game

Martin 21 Reputation points
2020-11-02T09:13:41.727+00:00

Hello,

I would like to create an android game using Socket.IO on Azure.

I was not able to connect through WebSockets and later discovered that it is not supported on Linux free tier (along with CORS). Express server app part was working fine.

I do have trouble finding up-to-date resources on how to set it up correctly on the Windows server (if it is still not possible to do it via Linux).

Could you please point me to the right direction?

  • is it possible to do it via Linux server while supporting CORS?
  • if I need Windows server, what extra steps do I need to take to make working localhost app work on windows server? - To be clear I have very little dev ops knowledge.
    For example do I need web.config?

Thank you!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,883 questions
0 comments No comments
{count} votes

Accepted answer
  1. SnehaAgrawal-MSFT 21,686 Reputation points
    2020-11-05T07:00:21.06+00:00

    Thanks for reply! If using Node.js you can verify web.config settings as below:

    1. For WebSockets to function correctly with Node.js applications, the web.config must contain the following entry. <webSocket enabled="false"/> As this disables the IIS WebSockets module, which includes its own implementation of WebSockets and conflicts with Node.js
      specific WebSocket modules such as Socket.IO. If this line is not present, or is set to true, this may be the reason that the
      WebSocket transport is not working for your application
    2. Normally, Node.js applications do not include a web.config file, so Azure Websites will automatically generate one for Node.js
      applications when they are deployed. Since this file is automatically generated on the server, you must use the FTP or FTPS URL for
      your website to view this file. You can find the FTP and FTPS URLs for your site in the classic portal by selecting your web app, and
      then the Dashboard link. The URLs are displayed in the quick glance section.

    Please check below links for more details on this:

    https://github.com/projectkudu/kudu/wiki/Using-a-custom-web.config-for-Node-apps?WT.mc_id=-blog-scottha

    https://github.com/uglide/azure-content/blob/master/articles/app-service-web/web-sites-nodejs-chat-app-socketio.md#troubleshooting

    https://www.hanselman.com/blog/enabling-websockets-for-socketio-node-apps-on-microsoft-azure

    Let us know.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 21,686 Reputation points
    2020-11-03T18:12:22.527+00:00

    Thanks for asking question! If I have understood right, you are using azure web app? If so, Yes As mentioned in this doc

    “Web Sockets are not currently supported for Linux apps on Free App Service Plans. We are working on removing this limitation and plan to support up to 5 web socket connections on Free App Service plans.”

    In order to enable for Windows, you may want to know Socket.IO uses WebSockets, which are not enabled by default on Azure.

    You can enable WebSocket support using the Azure Portal. Please see the steps below.

    • In the Azure portal, click on configuration > General settings from the SETTINGS menu.
    • Under Platform settings enable Web Sockets to On
    • Click Save.

    Reference: https://video2.skills-academy.com/en-us/azure/app-service/configure-common#configure-general-settings

    37241-inkeddemo12-li.jpg

    You may also refer to Enabling Websockets for Socket.io Node apps on Microsoft Azure

    To add more Azure Web App doesn't bind loaclhost or 127.0.0.1 to your website, and only ports 80 and 443 are public-facing and this maps to a specific port for your app to listen to, retrievable via process.env.PORT. So you'd need to replace

    var socket = io('http://localhost:3001');

    with

    var socket = io('http://<your app name>.azurewebsites.net');

    And if your server side and client side is in the different domain, you'd also need to enable CORS on the server side.

    You may refer to below doc link for enabling it from Azure Portal.
    Refer to : https://video2.skills-academy.com/en-us/azure/app-service/app-service-web-tutorial-rest-api#enable-cors

    Let us know Incase issue persists.

    0 comments No comments

  2. Martin 21 Reputation points
    2020-11-04T09:43:31.88+00:00

    I think the problem might be the missing web.config then. Is that so? Could you please tell me what kind of settings does it need to include?

    Thank you very much!

    0 comments No comments

  3. Martin 21 Reputation points
    2020-11-05T10:11:06.683+00:00

    Thanks a lot!

    I was able to make it work with your help :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.