I’ve been looking at gevent-socketio and was wondering how do I broadcast to an specific user. Lets say I want to send a notification to userX when userY submits data. The examples broadcast messages to all users on a chatroom, but still can’t figure out how to broadcast and event to an specific user. Do I need to create a custom Broadcast Mixin?
Share
If you want to implement a special broadcaster, or a special room, you will need to implement your own Mixin. I just added the ‘session’ attribute to the Namespace and Socket object.. on which you can set whatever information you want (it’s a dictionary). I suggest having an event that will set the nickname on, say,
self.session['nickname'], and then a function similar tobroadcast_event()(on the BroadcastMixin), that will loop through all the sockets, check its session to verify if the socket belongs to that particular user, and send the packet in if so.Take a look at the code. It is quite simple to use. You just need to understand the Socket / Namespace relationship.