I tried the followings but it does not return the url as string.
io.on('connection', function (socket) {
console.log(socket.handshake.url)
})
it prints something like "/socket.io/?EIO=3&transport=polling&t=M5blR4u". How do I get a url like "http://192.168.2.1:3600/app"?
Do I really have to send the url from the user side with window.location?
答案 0 :(得分:0)
您需要使用socket.handshake.headers.host
io.on('connection', function (socket) {
console.log(socket.handshake.headers.host)
});
,输出为:
localhost:8560
或者您可以使用handshake.referer
来完成这项工作。
更多详情:Socket.io Documents