Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  45] [ 6]  / answers: 1 / hits: 17951  / 11 Years ago, thu, august 15, 2013, 12:00:00

How do I detect if the server is offline, or for some other reason cannot connect. My code looks something like this.



this.socket = io.connect(connectionInfo, {
reconnect:false
});


It does not throw any error, so a try/catch clause is not working.


More From » node.js

 Answers
16

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


[#76349] Tuesday, August 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jackie

Total Points: 442
Total Questions: 107
Total Answers: 94

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
jackie questions
Sat, Sep 18, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
;