Socket.io connect with server offline

Since the 1.0 update, connection events are different. read this page for more info: http://socket.io/docs/migrating-from-0-9/

In my case, i could detect a connection error like so:

var manager = io.Manager('http://'+window.location.hostname+':3000', { /* options */ });
manager.socket('/namespace');
manager.on('connect_error', function() {
    console.log("Connection error!");
});

this.socket = io.connect('http://'+window.location.hostname+':3000');

Use

  • this.socket.on("connect", callback) to catch connection events
  • this.socket.on("disconnect", callback) to catch disconnection events
  • this.socket.on("connect_failed", callback) to catch failed connection attempts
  • this.socket.io.on("connect_error", callback) to catch if the server is offline

You can find all events, at https://github.com/LearnBoost/socket.io/wiki/Exposed-events


If your server is offline and Client tries to connect use:

socket.on('error', function (err) {
    console.log(err);
});

So Client knows he can not reach the server.