AJAX Push 需要付出什么才能让网页更具交互性?

发布于 2024-11-08 16:03:01 字数 298 浏览 0 评论 0原文

(抱歉,如果该主题的标题不正确,如果有人帮助我使其与我在下面解释的内容更加相关,我将不胜感激)。

最近,我对了解 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情感失落者 2024-11-15 16:03:01

我真的不明白“ajax推送”是怎么一回事。我知道长轮询,我认为这是一样的。

长轮询的缺点是您的服务器可能会打开大量未完成的请求。不是套接字,而是实际的请求。长轮询的思想:

  1. 客户端向服务器发出请求,
  2. 服务器不响应(未完成请求),
  3. 服务器等待,直到有东西要告诉(客户端)
  4. ,当服务器收到新信息(来自另一个客户端或其他地方)时它将该信息打印给所有等待的客户端(可能很多!)并完成请求
  5. 客户端收到该信息并立即发出另一个请求(使用新的时间戳和/或哈希值等)

缺点:如果 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 标头 => 大量开销)。

示例说明
这个例子非常(太)简单:

  1. 您(客户端)向服务器发出请求以获取当前信息
  2. 服务器为您提供该信息和时间戳
  3. 客户端接收信息,使用它(显示消息)并使用时间戳发出新请求
  4. 服务器比较客户端时间戳和服务器时间戳(在本例中为文件的filemtime
  5. 如果文件更改比客户端时间戳更新:打印新文件内容
  6. 客户端收到该信息和新的服务器时间戳
  7. 再次执行步骤 3 等

步骤 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:

  1. Client makes request to Server
  2. Server doesn't respond (doesn't finish the request)
  3. Server waits until there's something to tell (to the Client)
  4. When the server receives new information (from another Client or somewhere else) it prints that information to all waiting Clients (can be a lot!) and finishes the request
  5. Client receives that information and immediately makes another request (with new timestamp and/or hash etc)

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:

  1. You (Client) make a request to Server to fetch current info
  2. Server gives you that info and a timestamp
  3. Client receives info, uses it (show message) and makes new request with timestamp
  4. Server compares Client timestamp with Server timestamp (filemtime of a file in this case)
  5. If file change is newer than Client timestamp: print new file contents
  6. Client receives that info and the new Server timestamp
  7. Step 3 again etc

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).

硪扪都還晓 2024-11-15 16:03:01

这可能会帮助您开始:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文