GAE通道API重新连接
我正在 GAE 及其 Channel API 之上开发一个聊天应用程序。我已经研究了文档和提供的示例,还查看了这里的一些答案,但我仍然不觉得我了解 clientId/token 机制的全貌。
1)。该令牌的有效期为 2 小时,因此当它过期时我必须请求一个新的。我还将通过客户端 ID 参数在我的处理程序上获得断开连接状态。那么这是否意味着通道此时已关闭,并且通过请求新令牌我基本上是在创建一个新通道?因此,此时我可以使用哪个客户端 ID(旧的还是全新的)并不重要? GAE 还会将此视为正在创建的新频道吗?
2)。如果用户在令牌过期之前离开我的页面(我将收到断开连接状态)。然后回来(仍在 2 小时窗口内),我可以使用旧令牌将他重新连接到同一频道(假设我将它们放在 cookies 中)吗?如果是,那么 GAE 不会将此视为正在创建的新通道?
3)。如果上述问题的答案是肯定的,那么我可以在服务器端垃圾收集断开连接的客户端 ID 和令牌,并将它们分发给新连接的客户端。在这种情况下,如果用户返回我的页面并且他的旧客户端 ID/令牌已被其他人使用,他只会从池中收到另一对。或者这是每页一个频道规则生效的地方?
预先感谢并欢呼, 阿列克谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答:
1) 是的,无论您重复使用现有的客户端 ID 还是新的客户端 ID,您都需要为创建新频道付费。
2) 是的,您可以使用现有令牌重新连接,并且无需为创建新通道付费。服务器上的 create_channel 调用是有成本的;您在客户端上执行的任何操作都是免费的。
3)你可以这样做。请注意,如果您有多个客户端尝试使用同一令牌进行连接,您将得到不可预测的结果。
希望有帮助!
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!