这应该会有帮助,https://github.com/LearnBoost/socket.io/wiki/Authorizing
您可以跟踪所有会话变量,并使用握手数据中提供的以下内容的组合来唯一标识用户
{
headers: req.headers // <Object> the headers of the request
, time: (new Date) +'' // <String> date time of the connection
, address: socket.address() // <Object> remoteAddress and remotePort object
, xdomain: !!headers.origin // <Boolean> was it a cross domain request?
, secure: socket.secure // <Boolean> https connection
, issued: +date // <Number> EPOCH of when the handshake was created
, url: request.url // <String> the entrance path of the request
, query: data.query // <Object> the result of url.parse().query or a empty object
}
Run Code Online (Sandbox Code Playgroud)
这个示例也可能有帮助,只需让您的非浏览器客户端以不同的方式提供信息即可: