【发布时间】:2012-06-02 00:50:27
【问题描述】:
如何在 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.
//...........
}
我读过 http://www.danielbaulig.de/socket-ioexpress/ ,但我不需要node.js上的会话管理,只需要像connect.sid一样在cookie中添加一个socket.io客户端ID值。
【问题讨论】:
标签: node.js cookies express socket.io