html5 – MessageChannel和WebSockets之间的区别?

前端之家收集整理的这篇文章主要介绍了html5 – MessageChannel和WebSockets之间的区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法弄清楚MessageChannel和WebSockets之间有什么区别?

我需要以下要求:

>尽量减少延迟
>全双工
>最小标头数据长度

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

解决方法

HTML5 Web Messaging API可用于在浏览器中加载的独立代码段之间进行通信(规范称它们为“浏览上下文”).例如,如果您的网页包含< iframe>,并且您希望在其与外部代码之间进行安全通信,则可以使用Web Messaging.从Opera dev门户网站考虑 this explanation

Channel messaging is particularly useful for communication across
multiple origins. Consider the following scenario. We have a document
at 07002 containing content from
07003 embedded in one iframe,and content from
07004 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.

With channel
messaging,07004 and
07003 can communicate directly.

Web Sockets API可用于在浏览器中加载的代码与服务器之间进行通信.所以它有一个完全不同的目的.由于您提到了低延迟和“全双工”的要求,我假设您的意思是客户端 – 服务器通信,因此您正在寻找Web套接字.

原文链接:https://www.f2er.com/html5/168340.html

猜你在找的HTML5相关文章