On May 17, 8:33 am, Veeru <[email protected]> wrote:
> Ok, one question here, am setting a cool_id to the socket, then later on
> how can i retrieve this socket from another socket. i.e i want to send a
> message from a socket to this particular socket. how to do that?
You could just have a global object that contains all of the currently
connected users. Example (assuming server is a tcp server):
var users = {};
server.on('connection', function(socket) {
var id = socket.remoteAddress + ':' + socket.remotePort;
socket.cool_id = id;
users[id] = socket;
function removesock() {
if (users[id])
delete users[id];
}
socket.on('end', removesock);
socket.on('close', removesock);
});
Then you can just look up the id in `users` and access the socket
object directly if they're still connected.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en