无法使用本地主机上的node.js将消息发送给不在线的人

我有节点和运行与socket.io。 我能够发送消息给在我的服务器上联机的人(谁的套接字连接打开)。 但是,当我尝试发送多个人与至less一个离线它不经过。 如果所有都在线,它会通过。

任何帮助如何解决这个问题?

client.on('message_from_client',function(data){ for(var i=0;i<data.length;i++){ if(data[i].message_to!=''){ client.emit("update_message_from_server", data[i]); if(data[i].message_to != client.username){ var message_to = data[i].message_to; var array =data[i]; redisClient.SISMEMBER('online',message_to,function(err,reply){ if(reply!=0){ redisClient.get(message_to,function(err,reply2){ if(reply2!=null){ io.sockets.sockets[reply2].emit("update_message_from_server",array ); } }); }else{ console.log("Offline"); } }); } }else{ client.emit("update_message_from_server", data[i]); } } }); 

数据是一个JSON对象。 如果我有任何数据[我] .message_to离线我只能发送到客户端,但没有其他套接字。 如果我有网上所有条目,我可以将它发送到客户端和其他套接字

我想通过其他方式来做到这一点

 client.on('message_from_client',function(data){ alldata = data.data; console.log(alldata); alldata = JSON.parse(alldata); alldata.forEach(function(data){ if(data.message_to!=''){ client.emit("update_message_from_server", data); if(data.message_to != client.username){ redisClient.SISMEMBER('online',data.message_to,function(err,reply){ if(reply!=0){ redisClient.get(data.message_to,function(err,reply2){ if(reply2!=null){ io.sockets.sockets[reply2].emit("update_message_from_server",data ); } }); }else{ console.log("Offline"); } }); } }else{ client.emit("update_message_from_server", data); } }); });