2
votes

I have an application that uses channel API. The connections should be always alive (24x7) and I have implemented it in such a way that every time a channel gets disconnected, a new channel is created automatically. This works fine most of the times but I have scenarios where the onError() method does NOT gets called (E.g. Connected WIFI change, or Computer going to sleep and coming back). And my JS app falsely assumes that the channel is still alive when it is not.

One solution I thought of is to ping the server asking to send a message. Like a Keep Alive. But this is a big load for the server. (E.g. 1000 clients sending ping requests every 10 seconds is like 100 requests per second)

So I was wondering if there is a way to check if the connection is alive locally so that I wouldnt do a DoS attach on my server unintentionally.

Thanks

2

2 Answers

3
votes

You could create a GAE cron job that tells your server to send out keep-alive messages instead of having clients request it. That way regardless of the number of clients you have, you only have 1 request every 10 seconds.

You'll need to store your list of active clients in memacache/datastore though.

0
votes

I afraid there are no options but to ask server to send a message and check if it comes back in reasonable timeframe.

Your JS app can periodically ping some small (empty) static file (may be even outside of GAE) to check if connection was broken or computer went sleeping. That can be cheaper but would not give you 100% guarantee.