0

I have an app that supports a two way connection between a "master" device and multiple "remotes" using the Google App Engine Channel API. To conserve data consumption, the "master" only sends it's data to the remote devices who have been noted in a datastore entity. It Looks like this:

{"ag5zfnBhbmRvcmEtaG9tZXIVCxINU29ja2V0U2Vzc2lvbhjZswEMremote1": "AHRlWrqfFk1Od_9FMObXMnbQRV0NPlAD41aRaYCZ8-dzpAV4aZI-6XjGqhlRBbGL8P4slwTUTw4mI2Mb8VgqWSnMbNyO7ewRHCwVnqCvY9vA-XS4vyESFlNS3nRbdeEjuCXEXMSMxiguixfjPDF5fiseQkXm2SOp2c0YD6onfM7PpN6gGDicH5A", "ag5zfnBhbmRvcmEtaG9tZXIVCxINU29ja2V0U2Vzc2lvbhjZswEMremote0": "AHRlWrr5tXCamZ5fN4z8LUM1Wj_60GFNYS7kOEokAM_QeAAL7nlYo5EDuYeEpz_kepwK-k1kQ543jDeTLmUXws9n_3L-ty1rsYUN3SIILfaf4_4UXDVujj6tWed2nmXvbZ8ScX7dOilJBjc_xdvIu6NRDhqe-Pt1oinRXcsAc_NpDFQEOs_5bH8"}

It is simply a key that matches channel keys to tokens. The entity then can also determine which remotes are online and which can be reused and when they expire. They are added using the channel presence inbound handler and removed from the entity by its disconnect handler as well. However, because these devices may disconnect at anytime it isn't practical to recreate a channel token for each remote. Thus when connecting to the server, the server checks if any old tokens that haven't expired are not in use and instructs the remote device to use it by returning the old channel token via the key to token lookup in the datastore entity.

While the channel receives data as it should, the channel presence does not receive the request that it is connected. More interestingly, it never gets a ping when the remote is disconnected either which is most likely due to the unbeforeload issue in safari for the iPhone (the remote platform). However in the dev-server it works perfectly. Is this a bug or is it possible that reusing tokens in this manner is not reliable.

NOTE While i could just update the datastore of the presence of the new remotes upon determining if the remote should use an old or new token i'd rather use the channel presence as a cleaner method in verifying that the socket did in fact connect with the client.

EDIT Furthermore i am finding that if a remote token has been inactive for about 4-8 minutes before another remote tries to use it, this phenomenon does not occur.

EDIT2 In addition, I have noticed that when using an iPhone the channel almost always triggers its onerror handler a few minutes after a reliable connection regardless of using a new or old token. However, on a laptop this does not occur.

Hunter Larco
  • 785
  • 5
  • 17
  • I'm pretty sure that the documentation says channels aren't reusable. Note that the dev_server channel implementation (uses frequent polling) is entirely different from the actual production implementation (using comet). – dragonx Jul 06 '13 at 16:01
  • But it says they have an expiration time that you can set. Wouldn't one imagine that if the expiration hasn't been met and the server hasn't closed the connection, it has only been dropped by the client then it can be reconnected to on the client side? – Hunter Larco Jul 06 '13 at 16:33
  • Probably not. TCP requires an IP address and a port number for a socket. If the client loses track of this information, it's gone. If the connection has been disrupted but the client still considers the socket open, then communications will still work after it's reconnected. You can't arbitrarily reconnect from another client. – dragonx Jul 06 '13 at 16:43
  • so to understand: lets say a token has 24 hours before it expires. The client connects to the token but an error is thrown and it is disconnected. Are you saying it cannot reconnect to that token? – Hunter Larco Jul 06 '13 at 18:31
  • 1
    Actually, if you searched SO first, you might have found this http://stackoverflow.com/questions/17310267/can-google-app-engine-channels-be-reused/17495945#17495945 – dragonx Jul 06 '13 at 19:57
  • 1
    i had found it, but many other sources said it was possible and the ambiguity of the response made me skeptical, however i thank you for the reference. It seems foolish not to allow the same token to be reused. Lets say for instance if the user refreshes the page – Hunter Larco Jul 06 '13 at 21:16

0 Answers0