更新时间:2022-06-07 21:27:38
在访问 id
字段之前,您应该等待 connect
事件:
You should wait for the event connect
before accessing the id
field:
通过这个参数,您将访问 sessionID
With this parameter, you will access the sessionID
socket.id
客户端:
var socketConnection = io.connect();
socketConnection.on('connect', function() {
const sessionID = socketConnection.socket.sessionid; //
...
});
服务器端:
io.sockets.on('connect', function(socket) {
const sessionID = socket.id;
...
});