MrGlass MrGlass - 1 year ago 85
Node.js Question client to client messaging

I'm having trouble getting basic client to client (or really client->server->client) working with Heres the code I have right now:

io.sockets.on('connection', function (socket) {


for(userID in users) {
io.sockets.socket(userID).emit('message', { msg: 'New User Connected succesfully' });
socket.emit('message', { msg: 'Connected succesfully' });

socket.on('my other event', function (data) {

From my understanding, that should send the new user message to every connected user (individually, since i want to do actual individual messages later). Instead, I only get the 'connected successfully' message at the end. I don't get any errors or other negative indicators from my server or client.

Any ideas of why
doesn't work or what to use in its place?

mak mak
Answer Source


users.push(socket); // without .sessionId

for (var u in users)    {
   // users[u] is now the socket
   users[u].emit('message', { msg: 'New User Connected succesfully' });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download