Inbar Cheffer
Inbar Cheffer

Reputation: 2267

How can I make my flask server emit messages through flask socket-IO to specific client

I cant find any good documentation about this topic.

I have a server that provides authentication to clients and a simple REST API.

The server also running on a background_thread a socket-IO connection for communication with computers.

I want to save every session that opened with a computer on the socket-IO in database, and when user click a button in some page then my server start emitting messages to a specific computer using his saved session id.

How can i do that?

Upvotes: 1

Views: 2388

Answers (1)

Miguel Grinberg
Miguel Grinberg

Reputation: 67507

The sid session id assigned to each client is also the name of a room that has only that client in it. To send an event to a client, just send it to a room with the sid that you want. For example:

emit('some-event', {'data': 'foo'}, room=sid, namespace='/test')

Upvotes: 4

Related Questions