Socket IO

9/24/23 requires 3.6+

pip install flask-socketio
pip install eventlet #seems to just use it if installed

Setup

from flask import Flask, render_template
from flask_socketio import SocketIO

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

if __name__ == '__main__':
    socketio.run(app)

In factories can do

socketio = SocketIO()
# then
socketio.init_app(app, cors_allowed_origins="*")

In other folder

  • If no namespace, uses global namespace

  • 'message' and 'json' special events to listen to for unnamed events

    • Use send for these sepcial events and emit for custom

Rooms

  • all clients auto join a room with their request.sid name

Send messages from a background function

Last updated