gmail如何实时查看gtalk状态?
如果我在世界各地有数千个联系人(假设),其中一个将其状态更改为离开或成为偶像,那么它会在我的浏览器中立即更改吗?
How is it that if I have thousands of contacts (let's suppose) all around the world and one of them changes their status to away or becomes idol that it will change immediately in my browser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它实际上不是即时,有一点延迟,基本上当您在浏览器中加载 gmail 页面时,您还下载了一个 javascript 文件,该文件通过 ajax 动态刷新内容。同样,如果您的联系人更改了 gtalk 状态,并且您在 gmail 中使用 gtalk 客户端,则下次您正在查看的页面向服务器请求更新时,该更改将会反映出来。它只是不断地检查服务器是否有变化(面向事件的范例在网络上并不流行)。
It isn't instant really, there is a small delay, basically when you load the gmail page in your browser you also download a javascript file that refreshes the content dynamically via ajax. Similarly if a contact of yours changes gtalk status and you're using the gtalk client in gmail that change will be reflected after the next time the page you're viewing asks the server for updates. It's just constantly checking with the server for changes (the event oriented paradigm isn't really prevalent on the web).
我不确定 gmail 使用的确切机制,但一个相当愚蠢的方法是让页面轮询(通过 XMLHTTPRequest,又名 AJAX 调用)服务器每 X 秒一次,以了解自 N 秒前以来联系人状态的变化...然后应用这些更改。
I'm not sure of the exact mechanism gmail uses, but a fairly dumb way would be to have the page poll (via XMLHTTPRequest, aka AJAX call) the servers every X seconds for a change in contact statuses since N seconds ago... then apply those changes.
Google 聊天系统基于 XMPP 协议,Gmail 聊天块就像另一个 XMPP 客户端(类似于 gtalk、pidgin、psi桌面)。 XMPP 使用 Bosh 扩展在浏览器上运行。虽然我确信谷歌一定是通过黑客攻击让它以自己的方式工作,但基本的想法仍然是一样的。
简而言之,当您的一位联系人更新他/她的状态时,它会被推送到 google chat xmpp 服务器,该服务器又将该信息推送到您的 Gmail 聊天客户端。
Google chat system is based upon XMPP protocol and Gmail chat block is just like another XMPP client (similar to gtalk,pidgin,psi for desktops). XMPP runs over browser using Bosh extension. Though i m sure google must have hacked to get it working in their own way, but underlying idea is still the same.
In short, when one of your contact update his/her status, it is being pushed to the google chat xmpp servers which in turn pushes that information to your gmail chat client.