javascript WebRTC 和 Websocket。有区别吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12739185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:00:31  来源:igfitidea点击:

WebRTC and Websockets. Is there a difference

javascripthtmlwebsocketsocket.iowebrtc

提问by AndrewMcLagan

I'm assuming that WebRTC is an API that decodes/encodes audio and video, although the communication between the server and the clients is done via web sockets, or some other network protocol? I'm a bit confused. Does WebRTC have its own communications protocol?

我假设 WebRTC 是一个解码/编码音频和视频的 API,尽管服务器和客户端之间的通信是通过网络套接字或其他一些网络协议完成的?我有点困惑。WebRTC 有自己的通信协议吗?

回答by josh3736

There's two sides to WebRTC.

WebRTC 有两个方面。

  1. JavaScript APIs (getUserMedia) that allow an app to access camera and microphone hardware. You can use this access to simply display the stream locally (perhaps applying effects), or send the stream over the network. You could send the data to your server, or you could use...
  2. PeerConnection, an API that allows browsers to establish direct peer-to-peersocket connections. You can establish a connection directly to someone else's browser and exchange data directly. This is very useful for high-bandwidth data like video, where you don't want your server to have to deal with relaying large amounts of data.
  1. getUserMedia允许应用访问摄像头和麦克风硬件的JavaScript API ( )。您可以使用此访问权限在本地简单地显示流(可能应用效果),或通过网络发送流。您可以将数据发送到您的服务器,或者您可以使用...
  2. PeerConnection,一种允许浏览器建立直接对等套接字连接的 API 。您可以直接与他人的浏览器建立连接并直接交换数据。这对于像视频这样的高带宽数据非常有用,您不希望服务器必须处理中继大量数据。

Take a look at the demosto see both parts of WebRTC in action.

查看演示以了解 WebRTC 的两个部分的运行情况。

So in a nutshell:

所以简而言之:

  • WebSockets allow full-duplex communication between a browser and a web server.
  • WebRTC's PeerConnectionallows full-duplex communication between two browsers.
  • WebSockets 允许浏览器和 Web 服务器之间的全双工通信。
  • WebRTCPeerConnection允许两个浏览器之间的全双工通信。

回答by oberstet

WebRTC uses RTP (a UDP based protocol) for the media transport, but requires an out-of-band signaling channel to setup the communication. One option for the signaling channel is WebSocket.

WebRTC 使用 RTP(基于 UDP 的协议)进行媒体传输,但需要带外信令通道来设置通信。信令通道的一种选择是 WebSocket。

回答by 3rdEden

Instead of peerConnectionyou can also look at the WebRTC data channel draft: http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-00which is basically bidirectional udp. Which can be a really valuable alternative to WebSockets as doesn't have the "negative" sides of a tcp connection.

相反的peerConnection,你也可以看看WebRTC数据信道草案:http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-00这基本上是双向的UDP。这可能是 WebSockets 的一个非常有价值的替代方案,因为它没有 tcp 连接的“消极”方面。

回答by Felix Hagspiel

No, Signaling is not defined by WebRTC.

不,信令不是由 WebRTC 定义的。

Here is an post by the IETF which explains it pretty good why it is not: http://www.ietf.org/mail-archive/web/rtcweb/current/msg01143.html

这是 IETF 的一篇文章,它很好地解释了为什么它不是:http: //www.ietf.org/mail-archive/web/rtcweb/current/msg01143.html

This means that you are free to choose how you exchange network information. I.e. you could use websockets, HTTP and even Email, but that would be a bit of a struggle :)

这意味着您可以自由选择交换网络信息的方式。即你可以使用 websockets、HTTP 甚至电子邮件,但这会有点困难:)