miguelgrinberg / python-socketio

Python Socket.IO server and client
MIT License
3.96k stars 587 forks source link

Enable emitting to single client in managers with `to=...` #1375

Closed rustworthy closed 1 month ago

rustworthy commented 1 month ago

IMPORTANT: If you have a question, or you are not sure if you have found a bug in this package, then you are in the wrong place. Hit back in your web browser, and then open a GitHub Discussion instead. Likewise, if you are unable to provide the information requested below, open a discussion to troubleshoot your issue.

Describe the bug Emitting to a sid from an external process (AsyncPubSubManager) will fan out the message to all the connected clients.

Expected behavior A message is only delivered to the sid if to=sid is specified.


Hello and thank you for this beautiful piece of software! I really love the ergonomics and the excellent docs.

Please see PR #1374

miguelgrinberg commented 1 month ago

You can use room to address an individual client or a room. The to argument was introduced in the main server and client classes, and it appears that I missed including it in the managers.

rustworthy commented 1 month ago

I would honestly expect it the other way round :sweat_smile: , meaning you can use to to address an individual client or a room even if under the hood a single client is a room with one participant. This may be even more confusing, if one is using both sending to individual sids and rooms in their main app.

Also for the context, I've been building a web app that communicates with the browser-powered app: it sends notifications to the client, but can also receive certain tasks. The web app will then queue these tasks and embed a sid value as part of a task/job payload. A worker will pull the jobs from the queue, process them and inform the client (using the to=sid just like we are doing it in the main server). This is where it turned out that all the clients are receiving the report from the worker.

updated the PR

EDIT: also updated the issue title, since it turns out emitting to a specific client is possible