可以做客户端 HTTP 推送吗?

发布于 2024-07-25 18:45:17 字数 410 浏览 4 评论 0原文

与服务器端推送几乎相反,也称为 Comet。 我想知道是否可以使用长期存在的 HTTP 连接将信息推送到服务器。

与简单的 XHR 不同,连接将保持活动状态,并且当用户完成操作等时,数据将定期传输到服务器。

使用标准技术,我不认为这是可能的,但我愿意接受有关可能的建议实现这一点的利用或巧妙的方法。 目的是完成向服务器的低延迟数据推送,以实现快速高效的单向流传输。

我对使用 flash/java 桥接的套接字实现不感兴趣,因为提供跨域策略或获取 java 签名很麻烦。 欢迎无需额外依赖即可工作的粗暴黑客。 最好用 javascript 来解决这个问题。

Pretty much the opposite of server-side push, also known as Comet. I'm wondering if it is possible to use long lived HTTP connections to push information to the server.

Unlike a simple XHR, the connection would be kept alive and data would be streamed to the server at intervals, as the user completes actions etc.

Using standard technologies I don't believe this is possible, but I'm open to suggestions on possible exploitations or ingenious ways of accomplishing this. The purpose would be to complete low-latency data pushes to the server for fast and efficient one-directional streaming.

I'm not interested in using socket implementations with flash/java bridges because of the hassle of serving cross domain policies or getting the java signed. Crude hacks that work without additional dependencies are welcome. Preferably the solution would be done with javascript.

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

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

发布评论

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

评论(4

一萌ing 2024-08-01 18:45:18

我曾经看过http://orbited.org/背后的家伙的演讲,

它是一个使用标准技术的js库要保持服务器和客户端之间的连接打开,您可以将内容下推。

I once saw a talk by the guy behind http://orbited.org/

It's a js library that uses standard technology to keep a connection open between the server and the client you can push stuff down.

清旖 2024-08-01 18:45:18

这可以通过几种方法之一来完成...

您可以保持连接打开并且进行 POST,或者我确信可以进行多部分 POST。

This can be done in one of a few ways ...

You can keep a connection open and do POST's, or I am sure it is possible to do a multi-part POST.

失去的东西太少 2024-08-01 18:45:18

这是这样做的:
http://www.speich.net/projects/programming/firebug-testing.php

看看这个:http://en.wikipedia.org/wiki/Comet_(编程))
并在 Firefox 上搜索 'x-mixed-replace'

进行 XHR。 必须直接使用它或抓取 XHR 对象来设置有趣的字段。 xhr.multipart=true 并使用 onload 处理程序,而不是 onreadystatechange。

服务器应返回 mime 类型为“multipart/x-mixed-replace”的数据。 加上一个多部分分隔符。 刷新以获取每次齐射的最后一个字节。 我仍在努力让它顺利。

Safari (~=chrome) 可以做到这一点,但细节有所不同。 当readyState = 3而不是4时调用您的处理程序。并且每次新文本都会附加到resultText,而不是单独执行。 无法让任何东西在 IE 上运行。

this does it:
http://www.speich.net/projects/programming/firebug-testing.php

and look at this: http://en.wikipedia.org/wiki/Comet_(programming))
and google around for 'x-mixed-replace'

Do your XHR on Firefox. Must use it directly or grab XHR object to set funny fields. xhr.multipart=true and use the onload handler, not onreadystatechange.

The server should return data with mime type 'multipart/x-mixed-replace'. plus a multipart separator. flush to get the last bytes out for each salvo. I'm still trying to get it smooth.

Safari (~=chrome) can do it but the particulars are different. Call your handler when readyState=3, not 4. And every time the new text is Appended to resultText, not all alone. Can't get anything to work on IE.

墨洒年华 2024-08-01 18:45:18

如果您正在寻找双向浏览器服务器通信,您可能正在寻找 WebSockets 。 有关可用的实现,请参阅维基百科文章的底部。

If you're looking for bi-directional browser-server communication, you're probably looking for WebSockets. See at the bottom of the Wikipedia article for available implementations.

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