4

Im using my GAE application on my phone. I face a problem in getting the disconnect notification to /_ah/channel/disconnected in channels api even if i manually close the socket by socket.close() function. the post occurs after a delay of say one minute. Does anyone know the way to speed things up? In my case socket.close() doesnt produce the channel disconnect notification(only in phone though.. it works perfectly from a laptop)!

Hari
  • 83
  • 2
  • 9

1 Answers1

4

The amount of time it takes the Channel API front-end servers to "realize" that a channel is disconnected is contingent on browser implementation.

On well-behaved browsers, we catch the beforeunload event and post a message to our front-end that says, "this client is going away." On other browsers, we may not get the event (or we may not be able to listen to it for various implementation reasons, like the browser sends it too often (FFFUUUU IE)) or once we get the event the XHR we send may get swallowed. In those cases, the frontend server realizes the client is gone because it fails to receive a heartbeat -- this is what's happening on your phone. (out of curiousity, what phone?)

Your case is interesting because you're explicitly calling onclose. The only thing this does is dispose the iframe that has the Channel FE code -- in other words, onclose just behaves as if the whole browser window was closed; it doesn't take advantage of the fact that the browser is still in a good state and could wait to close until a message is sent.

So I recommend two things: add a custom handler to your code (that does the same thing as your /_ah/disconnect handler) so you can just make an XHR when you know you're manually closing the channel. This is kludgy but functional. The bummer about this is you'll need to explicitly know your client id in your javascript code.

Second, add an issue to our issue tracker (http://code.google.com/p/googleappengine/issues/list) to request better disconnect notification when onclose is called explicitly.

Hope that helps; sorry there's not an easy answer right now.

Moishe Lettvin
  • 8,462
  • 1
  • 26
  • 40
  • Yeah i get your point. But still even if i add a custom handler and do the logic there, what if the browser beforeunload event happens and the channel get disconnected! Are you telling me to listen to the beforeunload event as well? Will this work without any mesh in the phone? – Hari Oct 13 '11 at 04:10
  • I just now found that onbeforeunload is not supported by safari running on iPad, iPhone etc. I think that is the problem which im facing. So i can add a custom handler as you have mentioned in your previous post, but when the user closes the browser or navigate to some other page then i ll not be able to listen to the event right? Is there any other way to get out of this? Many thanks – Hari Oct 13 '11 at 07:19
  • The way you described the problem, it sounded like you were manually calling close on the channel -- my thought was, if you were doing that, then you could also send a message to your app via XHR to say "I'm closing this channel." In the case that the browser closes and never calls onbeforeunload, though, you're right that there's no easy way to know it. That's why we use a heartbeat on our front-ends -- when we don't get the heartbeat for a minute, we close the channel and notify your application. – Moishe Lettvin Oct 13 '11 at 19:19