4

I'm working on a chat application on top of GAE and its Channel API. I have studied the doc and the provided examples, also looked through some of the answers around here, still I don't feel like I have the whole picture of the clientId/token mechanics.

1). The token is issued for 2 hours, so when it expires I have to request a new one. I will also get a disconnect presense on my handler with the client id param. So does it mean that the channel is closed at that point and by requesting a new token I'm basically creating a new channel? So it doesn't even matter what client id I can use at that point, old or completely new one? Also GAE will count this as a new channel being created?

2). If user goes away from my page before the token expires (I will receive disconnect presence). And then comes back (still inside that 2 hour window), can I reconnect him to the same channel with the old token (lets say I have them in cookies)? If yes, then GAE is not counting this as a new channel being created?

3). If the answer to the above question is yes, then can I garbage collect disconnected client ids and tokens at the server side and distribute them for new connected clients. In this scenario if user comes back to my page and his old client id/token is already used by someone else, he will simply receive another pair from the pool. Or is this the place when the rule one channel per page comes into effect?

Thanks beforehands and cheers, Aleksei

Megas
  • 73
  • 5

1 Answers1

7

Answers:

1) Yeah, whether you re-use an existing client id or a new one, you'll be charged for creating a new channel.

2) Yes, you can reconnect with an existing token, and you won't be charged for creating a new channel. The create_channel call on the server is the one that costs; anything you do on the client is free.

3) You could do this. Be aware that if you have multiple clients that try to connect with the same token, you'll get unpredictable results.

Hope that helps!

Moishe Lettvin
  • 8,462
  • 1
  • 26
  • 40
  • Concerning 2) and 3) see [this docs page](http://code.google.com/appengine/docs/python/channel/overview.html#Caveats). Basically if the connection goes down, you have to issue a new token. Reusing a token is essentially the same as having several clients use the same token. – westmark Jan 23 '12 at 15:03
  • @westmark: hmm, I see a contradiction with Moishe's answer who has first hands knowledge on gae and channel api and I don't see anything on that page to prove your point... – Megas Jan 25 '12 at 00:28
  • 1
    @Megas I remember messing around with channel API way back and once a user lost connection a new token had to be generated. Channel API refused to reconnect using the old token. Maybe that has been changed since then. I guess Moishe knows his stuff, disregard my earlier comment :) – westmark Jan 27 '12 at 07:37