我试图在断开连接事件被触发后,重新连接具有相同socket.id的套接字。以下是我的socket配置:
var http = require('http').Server(app);
var io = require('socket.io')(http);
var connect_clients = [] //here would be the list of socket.id of connected users
http.listen(3000, function () {
console.log('listening on *:3000');
});
在断开连接时,如果可能的话,我希望能够使用同一 socket.id 重新连接已断开的用户。
socket.on('disconnect',function(){
var disconnect_id = socket.id; //i want reconnect the users here
});
socket.id
将唯一标识一个 用户 而不是一个 _连接_。服务器将会为每个连接生成一个新的 id,你无法覆盖它。 - robertklepsocket.io-client
的默认设置是自动重新连接的(已在此处文件中记录了reconnection
选项)。 - robertklep