javascriptgoogle-app-enginechannel-apiajax-push

GAE Channel API - Check if the socket is alive from Javascript


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


Solution

  • 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.