AJAX推送是HTTP协议异常吗?

发布于 2024-08-22 17:42:45 字数 246 浏览 3 评论 0原文

在面向 Web 的应用程序中开发优雅的 Pub-Sub 架构是一个真正的挑战。 尽管有一些非常有趣的解决方案使用长轮询连接(例如 COMET)和重复超时(例如 js setTimeout)。恕我直言,AJAX 推送看起来仍然像是一层强制无辜 HTTP 协议的调整和黑客攻击。

那么您认为AJAX 推送是否是 HTTP 协议异常?

您可以在 Web 架构中考虑哪些其他替代方案?

Develop a elegant Pub-Sub architecture in web-oriented-apps is a real challenge.
Although there are some very interesting solutions using long-polling-connections (e.g. COMET) and repetitive-timeouts (e.g. js setTimeout). IMHO AJAX push still looking like a layer of tweaks and hacks forcing the innocent HTTP protocol.

So what do you think Is AJAX push a HTTP protocol aberration?

Which others alternatives you could consider in a web architecture?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

指尖上得阳光 2024-08-29 17:42:45

我以前见过的另一个选项是使用小型隐藏的 Java 或 Flash 通过普通套接字连接到远程服务器。然后,服务器可以随时通过这些套接字推送数据/事件,而无需客户端进行任何轮询。

在我看来,Flash 稍微好一些,因为它不需要签名的小程序(它会向用户弹出安全警告)。它以一种或另一种形式提供套接字已经有大约 9 年了,尽管直到 Flash 9 / AS3 才获得可用于连接到任何类型服务的“纯”套接字(之前它要求消息是以“空”数据包终止,这意味着您必须专门为闪存设计协议,而不是能够使用 XMPP 或 SMTP 或任何现有协议)

Another option I've seen used before is to use a small hidden Java or Flash to connect via plain sockets to the remote server. The server can then push data / events over these sockets at any time, without any polling from the client.

Flash is a little better IMO since it doesn't require a signed applet (which pops up security warnings for the user). It's had Sockets in one form or another for something like 9 years now, though it wasn't until Flash 9 / AS3 that you got 'pure' sockets that you could use to connect to any type of service (previously it required that messages be terminated with a 'null' packet, meaning you had to design your protocol specifically for flash, instead of being able to use XMPP or SMTP or any existing protocol)

喵星人汪星人 2024-08-29 17:42:45

您还可以选择哪些其他选择
考虑在网络架构中吗?

HTML 5 Web Sockets API服务器发送事件看起来很有希望为了未来。 IE 尚不支持 Web 套接字,服务器发送的事件仍处于实验阶段。 Douglas Crockford 的 JSONRequest 提案也将是 AJAX 推送的一个有趣的替代方案,但尚未实现在现代浏览器中。

目前,我将坚持使用 Comet

Which others alternatives you could
consider in a web architecture?

The HTML 5 Web Sockets API and Server-sent Events look promising for the future. No IE support for Web Sockets yet, and Server-sent Events are still experimental. Douglas Crockford's JSONRequest proposal would also be an interesting alternative to AJAX push, but it is not yet implemented in modern browsers.

For the present, I'll stick with Comet.

朱染 2024-08-29 17:42:45

轮询是进行发布-订阅的网络架构方式。当客户端不经常轮询并且可以缓存和共享响应(例如博客的 rss feed)时,它效果很好。保持每个客户端打开 tcp 套接字(如 Comet)并不是使用 http 的理想方式。但是,如果您的应用程序在网络浏览器中运行,并且需要针对每个客户端进行频繁、独特的更新,那么这并不是一个坏方法。

Comet 和对每个客户端资源的轮询并不完全滥用 http 或 web —— 只是 http 和 web 是专门为在许多客户端之间共享相同的资源(即网页)而设计的,所以这就是它最好的工作方式。

Polling is the web-architecture way of doing pub-sub. It works well when clients poll infrequently and the responses can be cached and shared (for example, the rss feed of a blog). Keeping a tcp socket open per client, like with comet, is not the ideal way of using http. However, if your app runs in a web browser, and needs frequent, unique, per-client updates, that's not a bad way of doing it.

Comet and polling for per-client resources are not completely abusive to http or the web -- it's just that http and the web were designed particularly to share the same resources (ie web pages) among many clients, so that's the way it works best.

明天过后 2024-08-29 17:42:45

想想最常见的 Comet 实现,事实上,您必须欺骗浏览器,使其认为它正在接收多部分响应或 iframe 内的无限长 html,这一事实就足以引发人们对这是否是适当技术的怀疑。为了工作。

Just think about the most common Comet implementations, just the fact that you have to fool the browser into thinking that it's receiving a multipart response or an infinitely long html inside an iframe is enough to raise a flag on whether this is the appropriate technology or not for the job.

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