flask-sock icon indicating copy to clipboard operation
flask-sock copied to clipboard

Server-initiated broadcast to specific users

Open atarashansky opened this issue 3 years ago • 1 comments

Is it possible to send a message to a specific user as opposed to responding to an event triggered by clients?

atarashansky avatar Nov 08 '21 21:11 atarashansky

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.

miguelgrinberg avatar Nov 08 '21 23:11 miguelgrinberg