miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.31k stars 888 forks source link

trying to make socketio work with azure web app #1922

Closed ldariva closed 1 year ago

ldariva commented 1 year ago

Hi @miguelgrinberg ,

First of all I would like to say that I am a big fan of your work. It has saved my life hundreds of time.

I am developing a web app that among other thing receive an excel file and process it line by line. I created a progress bar which is updated using socket-io communication. In the development environment it works (and it was pretty easy to make it work). However when I upload my code to azure I am not being able to connect to the socket-io. I followed this example https://github.com/vjammar/aws-iot-python. As I am still in developing it I am using a free linux app (minimum resources) in azure. According to this page from MS the websocket is always enable now (some time ago, it was necessary to manually enable it)

This is how I configured the socket io on the flask app in init.py

from flask import Flask
...
from flask_socketio import SocketIO,emit
...
socketio = SocketIO(async_mode=None, logger=True, engineio_logger=True)

def create_app(config_name):

    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    with app.app_context():
        ...
        socketio.init_app(app)

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app

In the client side I am trying to connet to the socket io like this. Instances is

var socket = io.connect('https://<myapp>.azurewebsites.net:433/instances/',{
'reconnect': true,
'reconnection delay': 500,
'max reconnection attempts': 10
 });

When I try to submit the file I receive the following error

socket.io.js:3941 GET https://ampsystem.azurewebsites.net:433/socket.io/?EIO=4&transport=polling&t=OJsy8J6 net::ERR_CONNECTION_TIMED_OUT

Could you give me some hint? Thanks