node.js 的socket.io如何获取客户端的ip来标记客户socket
迷茫
迷茫 2017-04-17 16:38:26
0
3
761
想在server 端获得客户ip实现断线续连,发送私信的功能,问题是如何获取客户端的真实ip来标记socket?

var ChatterList=[];
io.sockets.on("connection", function(socket){
var newChatter={};
    newChatter.Soc=socket;//加入socket属性
   newChatter.IP=?; //如何获得客户端socket的ip?

   ChatterList.push(newChatter);//socket加入聊天列表


}
//给特定ip的socket发消息
ChatterList.forEach(function(){
    if(newChatter.IP===192.168.1.10){
        newChatter.Avail=false;
        newChatter.Soc.emit('test',"this is a test");
    };



)
      

主要问题是: newChatter.IP=?; //如何获得客户端socket的ip?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
黄舟

A typo?

ChatterList[0].Id   //  <--- 好歹给数组一个索引。
大家讲道理

It was a typo, I didn’t read it carefully, the question has been corrected, sorry!

黄舟

socket.request.connection.remoteAddress

Try this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template