a curious case of Flask-SocketIO

As a fullstack developer (do it all alone coding monkey), one day you are assigned with a task that requires realtime communication between browser and server.

So you typed ‘flask websocket’ in Google. The first page was filled with Flask-SocketIO. So you pip installed it and inside create_app, you did what the documentation said:

socketio.init_app(app)

then you run socketio.run() and open the example html came along with the chat demo.

To your surprise, the browser connected and was sending a ping in one second interval. But the server seemed like it was not receiving nor sending anything after WebSocket connection was established.

You spent several hours trying to find out why. Including all sorts of debug parameters:

socketio.init_app(app, engineio_logger=True)

and

socketio.run(
    app,
    host='0.0.0.0',
    port=5000,
    debug=True,
    use_reloader=True,
    log_output=True
)

But to no avail.

All of a sudden, you remembered that sometimes plugins do interfere with one another. So you moved your socketio.init_app(app) down to the bottom of the blob of ‘init_app’ from many many plugins.

And then, Flask-SocketIO started to spew ‘pongs’ in one second interval like they said in the demo.

You have no idea why but it worked.

FML

发表评论

电子邮件地址不会被公开。 必填项已用*标注