My app is in browser, which connects to socket.io server, it works fine, but, when client disconnect for a while ( sleep for example ) , the connection will be automatically closed by server, this is the default behavior for socket.io
How can I re-establish the connection at client side without refreshing the page? is there a status that would tell me that connection is currently off at client side? so that I re-connect when necessary?
I can't rely on an event, I think I need to know if connection is on or off in an easy way locally .. well?
socket.io
does reconnect automatically. To check if your socket is connected check socket.socket.connected
has Boolean value. See socket.socket.connecting
if you are trying to connect.
var socket = io.connect(''); //reconnects by default
console.log(socket.socket.connected);
console.log(socket.socket.connecting);
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