Difference between MessageChannel and WebSockets?

后端 未结 1 1604
我在风中等你
我在风中等你 2021-02-02 00:02

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

I need following requirements:

  • minimize delay
  • full-duplex
  • m
相关标签:
1条回答
  • 2021-02-02 00:47

    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:

    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 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.

    0 讨论(0)
提交回复
热议问题