Open perlish opened 6 years ago
Maybe you could do something like this? Not sure if it's the best way...
To send a message to a connection, you'd use the Sender
object.
So if you want to send by some kind of token, you need to associate those to Sender
s, e.g.
let mut user_connections: RwLock<HashMap<UserId, Rc<ws::Sender>>> = RwLock::new(HashMap::new());
Where I've added the Mutex because this structure is writable by multiple connections. Maybe your architecture has a way around it, or you have a better datastructure.
Then sending is just something like:
user_connections.get_mut().unwrap().get(&UserId::new(7)).unwrap().send("my data");
thanks, but i offered a new method https://github.com/housleyjk/ws-rs/pull/233
how it's possible to send message to specific connection_id or token? similar to broadcast but array of users, actually i need to send multicast message