开发者

Socket.io reconnect on disconnect?

开发者 https://www.devze.com 2023-03-03 06:57 出处:网络
Is something like this possible? socket.on(\'disconnect\', function(){ console.log(\'disconnected...\');

Is something like this possible?

socket.on('disconnect', function(){
    console.log('disconnected...');
    socket.connect();
    开发者_如何转开发socket.on('connect', function(){
    console.log('...reconnected');
    })  
})


Socket.io reconnects automatically (if you set the reconnect option, although it defaults to true), so you don't really need to do that.

Furthermore, there is a reconnect event which seems far more appropriate.

Also, set your event handlers independently, don't set the connect handler in the execution of the disconnect handler.

0

精彩评论

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

关注公众号