相关疑难解决方法(0)

Socket.IO身份验证

我试图在Node.js中使用Socket.IO,并试图让服务器为每个Socket.IO客户端提供一个标识.由于套接字代码超出了http服务器代码的范围,因此它无法轻松访问发送的请求信息,因此我假设它需要在连接期间发送.什么是最好的方法

1)通过Socket.IO获取有关谁连接的信息

2)验证他们说自己是谁(我目前正在使用Express,如果这让事情变得更容易)

authentication node.js express socket.io

115
推荐指数
4
解决办法
6万
查看次数

在Socket.IO上添加cookie值

如何在Socket.IO上添加cookie值?

io.sockets.on('connection', function (client)
{ 
    console.log(client.id); 
    client.handshake.headers.cookie.socketID = client.id;   // not work
 // client.handshake.headers.cookie("socketID",client.id);  //crash

    console.log(client.handshake.headers.cookie);
// The current output is:
//connect.sid=tI21xumy3u2n4QXO1GljmPAf.pzFQ1Xu%2B6bz36secu4VSCdSNU8PT1L44gQZ4kFUFQqQ
//this is express session id, and I also want to add client.id of Socket.IO. 

//...........
}
Run Code Online (Sandbox Code Playgroud)

我已阅读 http://www.danielbaulig.de/socket-ioexpress/ ,但我不需要在node.js上进行会话管理,但只需要在connect.sid中添加一个socket.io客户端ID值.

cookies node.js express socket.io

7
推荐指数
1
解决办法
2万
查看次数

node.js socket.io 获取cookie值

我想使用 socket.io 在节点服务器中获取 cookie 值

所以每次套接字向服务器发送消息时,我都会检查 cookie 的值

(我不想要会话 cookie)只有在 express 我得到 cookie

 router.get('/', function(req, res, next) {

  var cookie_id = req.cookies.userIDf;
  console.log(cookie_id);
   res.render('index', { title: 'Express' });
});
Run Code Online (Sandbox Code Playgroud)

它在这里工作,但使用 socket.io 我无法获得 cookie 任何解决方案?

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


var cookief =socket.handshake.headers['cookie'];
  console.log(cookief); // its give me session  id not the cookies
 });
Run Code Online (Sandbox Code Playgroud)

javascript sockets cookies node.js

4
推荐指数
1
解决办法
9765
查看次数