AJAX Push 需要付出什么才能让网页更具交互性?
(抱歉,如果该主题的标题不正确,如果有人帮助我使其与我在下面解释的内容更加相关,我将不胜感激)。
最近,我对了解 AJAX 推送及其所有内容非常感兴趣基本思想。我知道AJAX推送技术使网页在服务器端更具交互性,但在所有流畅的交互动作背后,显然有一些“艰苦的工作”,无论是在实现上还是在如何处理资源上。
简而言之,让我们忘记实现,我需要有人向我解释 AJAX 推送在服务器连接方面的工作方式、如何(或多少)使用资源,或者实现此时应考虑的其他一些方面方法。
我没有做太多研究,所以你有与此相关的任何文件,我非常乐意阅读。
(Sorry if the topic isn't titled properly, would appreciate if somebody helps me to make it more related to what I explain below).
Recently I feel very interested in getting to know AJAX push and all its basic ideas. I know AJAX push technique makes the web pages more interactive on the server-side, but behind all the smoothly interactive movements, there are apparently some "hard-work" behind the stage, in both implementation and how it deals with resources.
So in brief, let's forget about the implementation, I need somebody to explain me the way AJAX push works with respect to server connection, how (or how much) resources are used, or some other aspects that should be taken into account when implementing this method.
I haven't done much research so you have any documents related to this, I'm more than happy to read.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的不明白“ajax推送”是怎么一回事。我知道长轮询,我认为这是一样的。
长轮询的缺点是您的服务器可能会打开大量未完成的请求。不是套接字,而是实际的请求。长轮询的思想:
缺点:如果 500 个客户端都执行步骤 1 而没有执行任何操作否则,服务器有 500 个打开的请求,正在等待发送一些信息并结束这些请求。大多数服务器不允许 500 个打开的 HTTP 请求...
如果您有时间,您可能想阅读此 PDF。(虽然很长。)
PS。好处是您的服务器接收到的 HTTP 请求更少(这意味着 HTTP 开销更少),并且只有在有内容要发送时才会发送信息(这也意味着开销更少)。
编辑
长轮询示例: http://hotblocks.nl/tests/ajax/poller/ 及其源代码http://hotblocks.nl/tests/ajax/poller/callback.php?source
说明
优点:HTTP 开销更少,因为 HTTP 请求更少。假设用户数量是静态的(确实如此)并且为 500。
使用长轮询:500 个用户发出 1 个请求,然后等待......然后发生变化,所有 500 个请求都完成了(由服务器),然后由客户端“更新”(新的 HTTP 请求)。
优点:更少的请求(每个新信息每个用户 1 个)。
缺点:请求更长(空闲时间很长,这意味着打开的请求更多)。
没有长轮询:500个用户发出请求,服务器响应“没有新内容”,因此500个用户在500ms/1s/5s后发出另一个请求,服务器再次响应“没有新内容”等等,直到服务器有实际消息并且那么响应包含一些内容。即使如此,客户也会立即提出新的请求。
优点:向服务器发出快速、简短的请求,可以快速完成。
缺点:对服务器的请求很多很多(每个 HTTP 请求 => HTTP 标头 => 大量开销)。
示例说明
这个例子非常(太)简单:
filemtime
)步骤 4 之间的时间5 可能会很长。在活跃的聊天中,情况并非如此。 (不断添加新信息。)在多人游戏中,可能是(秒,而不是分钟)。
I don't really see how "ajax push" is a thing. I know long polling and I think it's the same.
The downside of long polling is that your server can have a lot of unfinished requests open. Not sockets, but actual requests. The idea of long polling:
The downside: if 500 clients all do step 1 and nothing else, the server has 500 requests open and is just waiting to send some information and end those requests. Most servers don't allow 500 open HTTP requests...
If you have time, you might want to read this PDF. (It's long though.)
PS. The upside is that your server receives less HTTP requests (which means less HTTP overhead) and that information is only sent when there's something to send (which also means less overhead).
edit
Long polling example: http://hotblocks.nl/tests/ajax/poller/ with source http://hotblocks.nl/tests/ajax/poller/callback.php?source
explanation
The upside: less HTTP overhead, because less HTTP requests. Let's say the amount of users is static (it is) and 500.
With long polling: 500 users make 1 request and then wait............ and then something changes and all 500 requests are finished (by the Server) and then 'renewed' (new HTTP request) by the Client.
Upside: less requests (1 per user per new information).
Downside: longer requests (very long idling, which means more open requests).
Without long polling: 500 users make a request, server responds with "nothing new", so 500 users make another request 500ms/1s/5s later and the server responds again with "nothing new" etc etc etc until the server has actual news and then the response contains something. And even then the clients immediately make a new request.
Upside: quick, short requests to the server that can be finished quickly.
Downside: many, many, many of those requests to the server (and every HTTP request => HTTP headers => MUCH overhead).
example explanation
The example is very (much too) easy:
filemtime
of a file in this case)Time between step 4 and 5 can be very long. In an active chat, it won't be. (New information is added all the time.) In a multiplayer game, it might be (seconds, not minutes).
这可能会帮助您开始:
http://www.icefaces.org/main/ajax -java/ajaxpush.iface
然而,这个链接在漫画书形式中更好 =))
http://www.ape-project.org /comics/1/Chapter-I-common-let-s-push.html
本质上它与 AJAX 非常相似,只是服务器现在可以与客户端通信,而不仅仅是接收客户端请求。
This might get you started:
http://www.icefaces.org/main/ajax-java/ajaxpush.iface
However this link is way better its in COMIC BOOK FORM =))
http://www.ape-project.org/comics/1/Chapter-I-common-let-s-push.html
Essentially its very similar to AJAX only the server can now talk to the clients rather than only having client requests.