问题描述
所有 HTTP 响应都需要客户端启动它们,即使是使用 AJAX 做出的响应.但是 GMail 的聊天功能能够接收来自其他用户的消息,即使我只是坐在舒适的电脑椅上观看但不与浏览器交互.他们是怎么做到的?
All HTTP responses require the client to initiate them, even those made using AJAX. But GMail's chat feature is able to receive messages from other users, even when I'm just sitting in my comfy computer chair watching but not interacting with the browser. How did they do it?
推荐答案
这种技术被称为彗星",也被称为服务器推送"、反向ajax"等.
That tech is known as "comet", but also as "server push", "reverse ajax", etc.
这是关于将数据从服务器推送到浏览器,保持 http 连接处于活动状态.在 维基百科文章 (英文版).
It's about pushing data from the server to the browser, keeping an http connection alive. Find more info on it on the wikipedia article (English version).
这里还有一个 相当不错的演示文稿,来自 DWR 的 Joe Walker,他在哪里谈论彗星.
Also here's a pretty good presentation with Joe Walker from DWR, where he talks about comet.
这篇关于GMail Chat 如何能够在没有客户端交互的情况下发出 AJAX 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!