Send message without request

171 Views Asked by At

How do you send a websocket server response (like a json blob) without receiving a message from the client.

For example, how would you make an actix webserver that sends a message to a connected client whenever it receives a message from an mpsc?

1

There are 1 best solutions below

0
Test On

The answer is to use the actix-ws (sub-)library. I found it too hard to do directly using the actix actors. This nice example gives a session object. You can call session.send(...) whenever you want, not just in the incoming message handler.