通过 http 传输二进制数据

发布于 2024-07-10 08:22:47 字数 440 浏览 6 评论 0原文

我正在研究将二进制数据流式传输到浏览器(通过 http)。 我正在寻找有关执行此操作的好方法的意见。 最终我将拥有一个实时数据源,我想操纵这些数据并将其(实时)显示在浏览器中。 Firefox 是第一位的,IE 就更好了...但我没那么挑剔。 我有一个 Firefox 插件可以满足我的需要,但我更喜欢用 javascript/html 编写的东西,无需用户安装任何插件即可工作。

我一直在研究 multipart/x-mixed-replace MIME/media 类型,它看起来在这个项目中可能有用,但我想在我花钱之前听听关于更好的方法(如果有的话)的意见沿着这条路走了很多个小时。

Flash 可能可以完成这项工作,但我还是想避免使用插件。 我想要尽可能简单的解决方案(不是吗?),最好只使用 javascript/html。

我也一直在研究 Comet,看看它能为我做些什么。

I am looking into streaming binary data into a browser (through http). I am looking for opinions as to good ways to go about doing this. Ultimately I will have a real time data source and I would like to manipulate this data and display it (in real-ish time) in a browser. Firefox comes first, IE would be nice... but I'm not that picky. I have a firefox plugin that does what I need, but I would prefer something written in javascript/html that would work without the user having to install any plugins.

I've been looking at the multipart/x-mixed-replace MIME/media type and it looks like it might be useful in this project, but I wanted to hear opinions on better ways to do this (if any) before I spend too many hours going down this path.

Flash would probably get the job done, but again, I'd like to avoid plugins. I'd like to have the simplest solution possible (don't we all?), ideally with just javascript/html.

I've also been looking into Comet to see what that can do for me.

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

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

发布评论

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

评论(5

撩人痒 2024-07-17 08:22:47

这在很大程度上取决于您想对数据做什么。 我假设渲染它。

Flash 可能是最简单的解决方案。 这是一个足够常见的附加组件,现在几乎每个人都应该拥有它; 因此您不会面临太大的不兼容风险。

JavaScript 还没有被认为是二进制数据处理的良好平台——因此,该领域还没有太多的发展。 我认为您不会为您想要的事情找到很多帮助。 尤其是当您了解渲染的要点时 - 除非您可以也许将每个二进制文件转换为canvas 脚本,因为它是 JavaScript 中唯一可用的动态图像。

IE 实际上可能是例外,因为您可能能够使用某些 ActiveX 对象来对某些文件类型完成此操作。 但是,然后你就删除了大多数其他浏览器。

A lot of this depends on what you want to do with the data. I assume render it.

Flash probably would be the simplest solution. It's a common enough add-on that just about everyone should have it by now; so you're not running much of a risk for incompatibility.

JavaScript just hasn't been considered much of a good platform for binary data handling -- so, there hasn't been too much development in the realm. I don't think you're going to find a lot of help for what you want. Especially when you get the point of rendering -- unless you can maybe convert every binary file to a canvas script, since it's about the only dynamic imaging available in JavaScript.

IE might actually be the exception, since you might be able to use some ActiveX objects to accomplish this for a few file types. But, then you cut out most other browser.

凑诗 2024-07-17 08:22:47

至于数据流和套接字样式连接,您可能需要查看 APE (Ajax Push Engine) 项目< /a>. 它允许您设置一个 HTTP 代理,您的 JavaScript 可以通过该代理进行真正的套接字连接。

至于数据到达后如何处理,我已经做了一个概念证明,展示了如何处理原始 PNG 数据、解析它并将其呈现给浏览器。 查看一下。

As for data streaming and socket style connections you might want to take a look at the APE (Ajax Push Engine) project. It allows you to set up a HTTP proxy that your JavaScript can connect through for true socket connections.

As for what to do with the data when it arrives, I've done a proof of concept showing how you can work with raw PNG data, parse it and render it to the browser. Check it out.

骑趴 2024-07-17 08:22:47

我之前必须对视频(即运动 jpeg)数据执行此操作。

我注意到你刚才说“二进制数据”......这是图像数据吗? 它是什么?

如今,multipart/x-mixed-replace 在很多浏览器中都可以正常工作。 我认为它甚至可能在更高版本的 IE 中得到支持。 大约 5 年前当我不得不实现这个功能时,它确实可以在所有版本的 Firefox 中运行。 基于 Webkit 的浏览器可能也受支持,包括 Chrome 和 safari。

然而,在我看来,这实际上只适合基于 LAN 的应用程序。 原因是您发送了大量数据。 您将每次发送整个图像,而不是发送连续帧之间的差异(如果是视频)。 根据用户数量,这也可能给服务器带来沉重的带宽负担。

因此,虽然 multipart/x-mixed-replace 是迄今为止最容易实现的,但它不一定是最合适的解决方案。 同样,这取决于您的原始数据类型。

对于视频,理论上你可以用 javascript 编写一些东西来做到这一点。 事实上,如果你用 google 搜索 javascript 视频播放器,你可以找到一些。 我怀疑它们的速度是否非常快,可能会给客户端机器带来沉重的负担。 不过,这似乎确实可行。

所以你的选择是:
1)内容类型混合替换
2)下载插件
原生浏览器插件(最快最高效)
基于 Flash 或 silverlight
3)基于Javascript的播放器

如果你想要的是视频最后一个选项,这是最前沿的
4) 基于 HTML5 的视频。 http://www.html5video.org/
由于标准仍在批准中并且浏览器支持有限,我不会
这个时候推荐一下。

I've had to do this exact thing before with Video (i.e. motion jpeg) data.

I note that you've just said "binary data"... is this image data or not? what is it?

multipart/x-mixed-replace works fine in alot of browsers these days. I think it might even be supported in the later versions of IE. It certainly works in all versions of firefox from around 5 years ago when I had to implement this. Webkit based browsers are probably supported too including Chrome and safari.

However, in my opinion this is really only suitable for a LAN based application. The reason is that you're sending ALOT of data. Rather than sending the differences between successive frames (if it's video that is) you'll be sending Whole images each time. Depending on the number of users, this could also place a heavy burden on the server for bandwidth.

So while multipart/x-mixed-replace is by far the simplest to implement, it's not necessarily the most appropriate solution. Again it depends on your raw data type.

For video you could in theory write something in javascript to do it. In fact, if you google for javascript video player you can find some. I doubt they are terribly fast and would probably place a heavy burden on the client machine. Still, it does seem doable.

So your options are:
1) Content type mixed-replace
2) Download a plugin
Native browser plugin (fastest most efficient)
Flash or silverlight based
3) Javascript based player

If it is video you're wanting The last option, which is on the bleeding edge is
4) HTML5 based video. http://www.html5video.org/
As the standards are still being ratified and browser support is limited I wouldn't
recommend it at this time.

夏尔 2024-07-17 08:22:47

您可以使用 Base64 将二进制文件转换为文本并将其发送到浏览器。 使用 IE,您可以将其直接转换为二进制,但我不确定您是否可以使用 Firefox 和其他浏览器执行此操作。 我确实看到了 Base64 enflate/deflate 的 jscripts 和一个名为 base64.js 的脚本,它也可能执行转换。

但是,您最好将二进制数据转换为 JSON 并使用 AJAX 传输数据,然后在浏览器中将其作为 JavaScript 对象进行处理。 Web 服务器将负责获取数据并将其转换为 JSON,因此无论您使用哪种编程语言,您都应该能够处理二进制文件。

You can use Base64 to convert the binary to text and send that to the browser. With IE you can convert it directly to binary, but I'm not sure if you can do it with Firefox and others. I did see jscripts for Base64 enflate/deflate and a script named base64.js which probably does the conversion as well.

However, you are probably better off converting the binary data into JSON and using AJAX to transfer the data and then processing it as a javascript object in the browser. The web server would be responsible for acquiring the data and converting it to JSON, so you should be able to process the binary regardless of which programming language you are using.

白鸥掠海 2024-07-17 08:22:47

我通常会避免使用 multipart/x-mixed-replace,因为它的浏览器支持相当粗略。 我知道我的相机的 multipart/x-mixed-replace 不适用于 IE 或较新版本的 Firefox(尽管显然有一个配置可以改变它)。

我认为小型 Flash 应用程序可能是您最好的选择之一。

I would generally avoid using multipart/x-mixed-replace, as it has pretty sketchy browser support. I know that my cameras' multipart/x-mixed-replace doesn't work on IE or newer versions of Firefox (although apparently there is a configuration thing to change that).

I think that a small Flash app may be one of your best options.

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