I'm working with socket.io and node.js and until now it seems pretty good, but I don't know how to send a message from the server to an specific client, something like this:
client.send(message, receiverSessionId)
.send()
.broadcast()
.broadcast()
Well you have to grab the client for that (surprise), you can either go the simple way:
var io = io.listen(server);
io.clients[sessionID].send()
Which may break, I hardly doubt it, but it's always a possibility that io.clients
might get changed, so use the above with caution
Or you keep track of the clients yourself, therefore you add them to your own clients
object in the connection
listener and remove them in the disconnect
listener.
I would use the latter one, since depending on your application you might want to have more state on the for the clients anyway, so something like clients[id] = {conn: clientConnect, data: {...}}
might do the job.