-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 a specific connected client #367
Comments
If you keep track of clients on connect, it's very easily done. This is more or less a duplicate of: #81 I took a similar approach to @michael and did something like this on connect, dirtying the ws object with an id... var id = 0;
var lookup = {};
wss.on('connection', function(ws) {
ws.id = id++;
lookup[ws.id] = ws;
[...]
} if you want to send a message to the client with id == 0, you'd just call... lookup[0].send('message'); There's probably a better way to do this, but it's working fine for me. |
Can you also send something to everyone without looping through the lookup? |
Hi, i have just used this method but basically what the following code does is: Client with tag connects to a server and is being remembered, client without tag just sends information with a specific destination which is being represented by that tag, so the role of the server is just to forward this info to a specific client `
` output after connecting 3 clients, 2 are listening 1 is sending - and it works fine but nothing is being sent to a specific client: |
@WiktorLigeza I think you're mixing id/tag. This is not an issue in this library, but your code. Try SO or google for help |
|
Is there any way of initiating a message to a connected client as opposed to replying to a message from a client ?
The text was updated successfully, but these errors were encountered: