v0.14.0: How to broadcast to all sockets #351
-
I read the discussion in #323 and it was discussed, that broadcast() will emit to the sender too. In the documentation of v0.14.0 it says "Broadcasts to all sockets without any filtering (except the current socket)."
As I'm new to Rust and socket.io I was digging through the examples, and also couldn't find an example for sending to all connected sockets, except from working around with (https://github.com/Totodore/socketioxide/blob/main/examples/private-messaging/src/handlers.rs):
Is there a reason to not have a brodcastAll method implemented, or did I miss it? Also the README could have the basic emit operations explained. I could also help with improving the documentation. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can use the io.emit method. This will emit on all sockets in the "/" namespace, you can also add more filter by using operators as usual ( I agree that it could be specified in the emit section of the documentation. Feel free to contribute if you want: |
Beta Was this translation helpful? Give feedback.
-
In my Axum application I have in the main method the following code to initialize the Socket.io:
my on_connect handler looks as follows:
When I have two clients connected to my server, the code above leads to the expected behavior. Every client receives a response once, independent of who has sent the event. So in my case, the first emit does not get sent to all the clients connected to the server. Not sure if I understood it correctly, or if I'm doing something wrong. |
Beta Was this translation helpful? Give feedback.
You can do that or use
io.emit
as I mentioned above.