Chat Rooms with Actix Websockets

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.

Thanks for all the help!

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 https://docs.rs/tokio/0.2.22/tokio/fn.spawn.html that there's #[tokio::main] above the main function, would this be a problem if I'm already using #[actix_rt::main]?

I've never used actix myself, but I hear it uses Tokio internally and that using Tokio should work fine inside actix.

I see, I'll look into it. Thanks!