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.
socket.io only works when connected to the internet #2309.
Problem: the socket is not able to connect Possible explanations: You are trying to reach a plain WebSocket server. The server is not reachable. The client is not compatible with the version of the server.
Use
this.socket.on("connect", callback)
to catch connection eventsthis.socket.on("disconnect", callback)
to catch disconnection eventsthis.socket.on("connect_failed", callback)
to catch failed connection attemptsthis.socket.io.on("connect_error", callback)
to catch if the server is offlineYou can find all events, at https://github.com/LearnBoost/socket.io/wiki/Exposed-events
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With