Hi I'm currently trying to use actix websockets to create a real-time messaging app and I was wondering how to group different clients together so that I can uniformly send a serverside message to be delivered to all of the clients inside a group. So far all I have is an echo server illustrated in the documentation but it seems as though I would be able to send messages from the server to the client through the ctx.text() method.
You could start a task with tokio::spawn that has a list of clients in each group, along with a sender to an mpsc channel for every client. Then whenever you want to broadcast a message, you send it to that task, which forwards it to everyone who should receive it.
Hi alice, could you show some code to illustrate what you mean? -I'm not very familiar with tokio. Also I noticed in tokio::spawn - Rust that there's #[tokio::main] above the main function, would this be a problem if I'm already using #[actix_rt::main]?