Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check socket.io connection locally?

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?

like image 703
simo Avatar asked May 31 '13 08:05

simo


1 Answers

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);
like image 164
user568109 Avatar answered Sep 22 '22 13:09

user568109