Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send message to specific socket #232

Open
perlish opened this issue Aug 28, 2018 · 2 comments
Open

send message to specific socket #232

perlish opened this issue Aug 28, 2018 · 2 comments

Comments

@perlish
Copy link

perlish commented Aug 28, 2018

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

@mverleg
Copy link

mverleg commented Dec 2, 2018

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 Senders, 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");

@perlish
Copy link
Author

perlish commented Dec 13, 2018

thanks, but i offered a new method #233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants