Reputation: 11
I have a flask application that I implemented socketio on. In the local debugger it works. Through IIS the connections are not stable. Here is a snip of the console:
The logs show my console log statements where someone is connecting and disconnecting a socketio connection. On the network tab I see this:
If I use eventlet with this, I get the same behaviors others have seen in here. IIS logs say you need to use eventlet. The results are identical between eventlet and gevent in terms of console messages. The only real different I see is in the IIS log file. Instead of saying you must use eventlet, it says this:
So of course I checked the documentation, there is no deviation between what is shown in the IIS docs and what I did. All steps were covered from what they provide.
init.py:
from flask import Flask, Blueprint, session
from flask_socketio import SocketIO
from flask_cors import CORS
socketio = SocketIO()
def create_app():
app = Flask(__name__)
app.config["DEBUG"] = True
app.config["SECRET_KEY"] = 'secret'
CORS(app)
socketio.init_app(app)
from project.routes import project_bp
from project.branch_bp.routes import branch_bp
app.register_blueprint(project_bp)
app.register_blueprint(branch_bp)
from project.branch_bp import events
return app
run.py:
from gevent import monkey
monkey.patch_all()
import logging
from project import create_app, socketio
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
app = create_app()
if __name__ == "__main__":
# logging.basicConfig(level=logging.NOTSET) # Set the logging level to DEBUG
logging.basicConfig(level=logging.DEBUG)
http_server = WSGIServer(('127.0.0.1', 5000), app, handler_class=WebSocketHandler)
http_server.serve_forever()
I have also seen this post:
Flask-Socket.IO (IIS): "WebSocket is closed before the connection is established."
This is the reason I moved over to gevent after eventlet failed. It took some time to get gevent working properly in the debugger, and then I just had the same issue in IIS after trying those steps and introducing a reverse proxy in IIS.
Has anyone ever gotten this to work?
Upvotes: 1
Views: 648