dis/reconnect clientside

86 views
Skip to first unread message

stefa_n

unread,
Oct 29, 2011, 12:47:56 PM10/29/11
to nowjs
Hi,
I would like to give a feedback (changing icon) when the connection to
the server gets lost. Is there a way to detect this?
Thanks.
Stefan

Steve Wang

unread,
Oct 29, 2011, 7:45:48 PM10/29/11
to nowjs
Try

now.core.socketio.on('disconnect', function () {
alert('Disconnected from server.');
});

and

now.core.socketio.on('connect', function () {
alert('Connected to server.');
});

That should do the trick.

stefa_n

unread,
Oct 30, 2011, 9:03:34 AM10/30/11
to nowjs
Yes, this does the trick.Thanks Steve.
For others reading this:You'll have to wait till NowJS has loaded
SocketIO, so put this in/after the ready-event.Take care that it's
executed only once as a reconnect will call ready again.
When connection really get's lost SocketIO throws an error:Firebug
soiws sth like (translated from german):The connection to ... was
disrupted while the page was loadingsocket.io.js, 2293, this.websocket
= new Socket(this.prepareUrl() + query);
A network-connection can fail anytime for all kind of reasons. I
wouldn'tsee this as a real programming-error. Is there a way to turn
this off orcatch it without delving into SocketIO?
Reply all
Reply to author
Forward
0 new messages