Hi, I am using the latest version of Socket.io 0.9 and I have encountered an issue with emitting to individual client. I have already tried a lot of research but nothing works except broadcast. This is my current code:
io.sockets.on('connection', function( socket ) {
var clients = {};
socket.on( 'subscribe', function( userID ) {
clients[userID] = socket.id;
});
// PHP post data
socket.on( 'notifyMsg', function( data ) {
var obj = JSON.parse( data );
for( var i=0; i<obj.info.notifyUserIDs.length; i++ ) {
console.log("output to = " + obj.info.notifyUserIDs[i])
var to = clients[obj.info.notifyUserIDs[i]];
if( to ) {
// Works for all clients
io.sockets.socket(to).broadcast.emit( 'notification', data );
// Does't work for individual client
io.sockets.socket(to).emit( 'notification', data );
}
}
});
I can’t get this to emit to specific client, hope someone could shed some light here.