flask-sock
flask-sock copied to clipboard
Server-initiated broadcast to specific users
Is it possible to send a message to a specific user as opposed to responding to an event triggered by clients?
It is, but the application has to handle it, this extension does not provide that as a feature. You have to store the ws
objects for your clients so that you can send data on the appropriate one. For example, you can have a global dict with the user ID as key, and the ws
object for that user as value. Then when you need to send a message to a specific user, you can look up the ws
object in this dict.
Also, you may also consider using the Flask-SocketIO extension, which is a much more advanced solution that provides access to individual users or groups of them.