You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then how should you handle the onclose event to reconnect? I don't see anything in the API docs like a 'connect' method... so would you have to create a new SockJS instance? In that case, how do you clean up all the event listeners you made for the old SockJS instance?
so would you have to create a new SockJS instance?
yes. it's similar to websockets API
In that case, how do you clean up all the event listeners you made for the old SockJS instance?
The naive assumption is that once you stop referring to the old sockjs instance it should be garbage collected. If that's not true - file a bug as this would be a memory leak!
This is perfectly fine. I would suggest some kind of delay and exponential backoff - you don't want to spin 100% cpu if the network is unavailable, right?
yea, it's on my todo already to set up exponential backoff, one of the first things I plan on doing after I finish my backend rewrite to use tornado.gen where possible.
Activity
majek commentedon Jan 11, 2012
You get the
onclose
event. Reconnection can't be done automatically by SockJS, so it's your responsibility to handle that accordingly.hunterloftis commentedon Jan 11, 2012
Then how should you handle the onclose event to reconnect? I don't see anything in the API docs like a 'connect' method... so would you have to create a new SockJS instance? In that case, how do you clean up all the event listeners you made for the old SockJS instance?
Thanks
majek commentedon Jan 11, 2012
yes. it's similar to websockets API
The naive assumption is that once you stop referring to the old sockjs instance it should be garbage collected. If that's not true - file a bug as this would be a memory leak!
joerussbowman commentedon Jan 13, 2012
I do just that with onclose, here's a sample of my javascript
majek commentedon Jan 13, 2012
This is perfectly fine. I would suggest some kind of delay and exponential backoff - you don't want to spin 100% cpu if the network is unavailable, right?
joerussbowman commentedon Jan 13, 2012
yea, it's on my todo already to set up exponential backoff, one of the first things I plan on doing after I finish my backend rewrite to use tornado.gen where possible.
knowitnothing commentedon Oct 24, 2013
I've commited a simple reconnector at https://github.com/knowitnothing/sockjs_reconnect