0

there is a similar question for nodejs but I need for python also

node.js socket.io How to emit to a particular client?

I want to broadcast a message to an specific client based on some condition using socketio and flask from the connected clients. Basically,

  1. How I can find the connected clients in socket io?
  2. How I can emit a message to an specific client?

Sample code for broadcast

@socket_.on('my_broadcast_event', namespace='/test')
def test_broadcast_message(message):
    session['receive_count'] = session.get('receive_count', 0) + 1
    emit('my_response',
         {'data': message['data'], 'count': session['receive_count']},
         broadcast=True)
Rabindra Nath Nandi
  • 1,433
  • 1
  • 15
  • 28
  • 1
    Duplicate of https://stackoverflow.com/questions/39423646/flask-socketio-emit-to-specific-user. Note that Flask-SocketIO uses python-socketio as a dependency. – Miguel Grinberg Nov 27 '20 at 23:46
  • 1
    Does this answer your question? [flask socketio emit to specific user](https://stackoverflow.com/questions/39423646/flask-socketio-emit-to-specific-user) – Hacker Oct 19 '21 at 21:44

0 Answers0