Search code examples
pythonflasksocket.ioreal-timeflask-socketio

Send data to all connected clients with interval. Flask-socketio


I am creating an online game with Flask on backend.
I have following code on client:

socket.on('get_update', function(data) {
    console.log(data);
});

On server-side, I need to send online_players(dict) to all connected clients with some interval(ex. 0.5 sec)
How I can do this with Flask?


Solution

  • Use celery periodic task with Flask-socketio. Create a periodic task which will run every second or 0.5 seconds in the background.