开发者

How do you get the request data with socket.io with node.js and express?

开发者 https://www.devze.com 2023-03-22 16:03 出处:网络
So I have this problem using express with socket.io. I think it is pretty self explanitory; I simply need to get the session and request parameter data to socket.io. This cannot be done on the client

So I have this problem using express with socket.io. I think it is pretty self explanitory; I simply need to get the session and request parameter data to socket.io. This cannot be done on the client side as some rooms are going to be private. Any solutions?

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

  socket.on('send message', function(data) {
    NEED USER ID STORED IN session.user
  }
})

app.get('/:roomid', function (req, res) {
  //req.session.user = THE U开发者_StackOverflowSER ID
  //req.params.roomid = THE ROOM ID
})


Socket.IO 0.7.7~ introduces a new property on the socket called handshake this is the data that we gather when the client does it's initial handshake request. It contains the headers, ip and some other stuff.

This wiki https://github.com/LearnBoost/socket.io/wiki/Authorizing touches the subject lightly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号