python socket.io How to emit to a particular client?

1.1k Views Asked by At

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)
0

There are 0 best solutions below