0

Currently I have the following situation. My socket.io (socket.io 1.1.0) application works, but when it fails it makes infinite amount of attempts to reconnect. I want to have some upper limit. Say if after 5 reconnects the app is still failing - then stop it and say the message to the user.

After searching for some time I thought that I was partially able to solve my problem with

var socket = new io.connect('http://localhost:8181', {
    'reconnect': true,
    'reconnection delay': 500,
    'reconnection limit': 5,
    'max reconnection attempts': 5
});

The problem is that it absolutely does not work. Application still tries to reconnect infinite amount of time. In addition I still have no idea how to make a callback when the number of reconnections was achieved.

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753

1 Answers1

1

The parameters were renamed (probably with socket.io 1.0 version). Try again with:

var socket = new io.connect('http://localhost:8181',
      {'reconnectionDelay': 500,
       'reconnectionAttempts': 5});

https://github.com/Automattic/socket.io-client#managerurlstring-optsobject

DerM
  • 1,497
  • 1
  • 14
  • 27