MessageChannel和WebSockets之间的区别? [英] Difference between MessageChannel and WebSockets?

查看:112
本文介绍了MessageChannel和WebSockets之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚MessageChannel和WebSockets之间有什么区别?

I can't figure out what is difference between MessageChannel and WebSockets?

我需要以下要求:


  • 最小化延迟

  • 全双工

  • 最小标题数据长度

这两项要求都满足吗?哪个更好?

Are both fullfil this requirements? Which is better?

推荐答案

HTML5 Web Messaging API 可用于在浏览器中加载的独立代码段之间进行通信(规范称它们为浏览上下文)。例如,如果您的网页包含< iframe> ,并且您希望在其与外部代码之间进行安全通信,则可以使用网络消息传递。考虑来自Opera开发门户的此解释

HTML5 Web Messaging API can be used to communicate between independend pieces of code loaded in the browser (specification calls them "browsing contexts"). For example, if your page contains an <iframe>, and you want to securely communicate between it and the outside code, you might use Web Messaging. Consider this explanation from the Opera dev portal:


频道消息对跨越
多个来源的通信特别有用。请考虑以下情形。我们在 http://socialsite.example 上有一份文件
,其中包含来自
http://games.example 嵌入在一个iframe中,内容来自
http://addressbook.example 在另一个。

Channel messaging is particularly useful for communication across multiple origins. Consider the following scenario. We have a document at http://socialsite.example containing content from http://games.example embedded in one iframe, and content from http://addressbook.example in another.

现在让我们说我们想要
发送消息从我们的地址簿网站到我们的游戏网站。我们可以
使用社交网站作为代理。但是,这意味着地址簿
获得与社交网站相同的信任级别。我们的社交网站
要么必须信任每个请求,要么为我们过滤它们。

Now let’s say that we want to send a message from our address book site to our games site. We could use the social site as a proxy. That, however, means the address book gains the same level of trust as the social site. Our social site either has to trust every request, or filter them for us.

但是,通过频道
消息传递, http:// addressbook。示例
http://games.example 可以直接通信。

With channel messaging, however, http://addressbook.example and http://games.example can communicate directly.

Web套接字API 可用于在浏览器中加载的代码与服务器之间进行通信。所以它有一个完全不同的目的。既然你提到了低延迟和全双工的要求,我认为你的意思是客户端 - 服务器通信,所以你正在寻找一个网络套接字。

Web Sockets API can be used to communicate between code loaded in the browser and the server. So it serves a completely different purpose. Since you're mentioning the requirement of low latency and "full-duplex" I assume you mean client-server communication, and so you're looking for a web sockets.

这篇关于MessageChannel和WebSockets之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆