GAE channel API reconnect

1.2k views Asked by At

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

1

There are 1 answers

3
Moishe Lettvin On BEST ANSWER

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!