5

Is something like this possible?

socket.on('disconnect', function(){
    console.log('disconnected...');
    socket.connect();
    socket.on('connect', function(){
    console.log('...reconnected');
    })  
})
davin
  • 44,863
  • 9
  • 78
  • 78
fancy
  • 48,619
  • 62
  • 153
  • 231

1 Answers1

12

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.

davin
  • 44,863
  • 9
  • 78
  • 78