Flask-socketio: How to emit message to specified client?

Created on 26 Jul 2017  路  2Comments  路  Source: miguelgrinberg/Flask-SocketIO

This example only work in broadcast.
https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/app.py#L17-L25

File "/home/ivan/github/microMsg-bot/server.py", line 32, in qr_callback
emit('qr', (uuid, status))
File "/home/ivan/.local/lib/python3.6/site-packages/flask_socketio/__init__.py", line 665, in emit
namespace = flask.request.namespace
File "/usr/lib/python3.6/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/lib/python3.6/site-packages/werkzeug/local.py", line 306, in _get_current_object
return self.__local()
File "/usr/lib/python3.6/site-packages/flask/globals.py", line 37, in _lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.

question

Most helpful comment

That example you referenced can be used to send to a specific client if you add room=sid as an argument. The sid value for a client is given to you in all event handlers for a client, you can get it as request.sid. Your application will have to store these sid values and map them to your users.

All 2 comments

That example you referenced can be used to send to a specific client if you add room=sid as an argument. The sid value for a client is given to you in all event handlers for a client, you can get it as request.sid. Your application will have to store these sid values and map them to your users.

thanks!

Was this page helpful?
0 / 5 - 0 ratings