tengo el siguiente servidor en node:
Código HTML:
var express = require('express'); var app = express(); var server = app.listen(3000); var link = require('socket.io').listen(server); var app_users={}; link.sockets.on("connection", function (user){ user.on("app_user",function (user){ app_users[user.id]=user; console.log("New user: "+app_users[user.id].id + " - " + app_users[user.id].username); }); user.on("mensajeNuevo", function (data){ var nombre ="diegoug"; for(var socketid in app_users){ if (nombre==app_users[socketid].username) { //link.to(socketid).emit(); link.sockets.sockets[socketid].emit("mensajeDelServidor", Object.keys(app_users)); user.emit("mensajeDelServidor", Object.keys(app_users)); } } }); user.on('disconnect', function () { delete app_users[user.id]; //console.log(link.engine.clientsCount); }); });
Gracias