gpt4 book ai didi

html - MessageChannel 和 WebSockets 之间的区别?

转载 作者:太空狗 更新时间:2023-10-29 13:22:12 32 4
gpt4 key购买 nike

我不明白 MessageChannel 和 WebSockets 之间有什么区别?

我需要满足以下要求:

  • 尽量减少延迟
  • 全双工
  • 最小 header 数据长度

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

最佳答案

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

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.

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

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

关于html - MessageChannel 和 WebSockets 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29620567/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com