问题描述
这听起来像是一个非常基本的问题,但我需要确认
This sounds like a very basic question, but I need a confirmation
- WebRTC 使用 TCP 还是 UDP 作为其对等传输?我如何知道吗?
- 我看了有可靠性模式和DTLS协议,怎么做它们会影响吗?
- 媒体和数据通道的这种传输是否相同?
- 如何在 TCP 和 UDP 之间切换?
我问这个是因为我知道浏览器对并行连接的数量有限制(我认为他们谈论的是TCP),而UDP连接可能没有限制.
I ask this because I know that browsers have a limit on the number of parallel connections (I think they talk about TCP), and maybe UDP connection is not limited.
推荐答案
它可以使用任何一个.默认情况下,优先使用 UDP,但根据连接的对等点之间的防火墙,它可能只能与 TCP 连接.您可以使用 Wireshark 来捕获数据包并验证使用的是 TCP 还是 UDP.在 Chrome 中,您还可以通过转到
chrome://webrtc-internals
来查看所选候选 (googActiveConnection
) 的详细信息.
It can use either. By default, preference is given to UDP, but depending on the firewall(s) in between the peers connecting it may only be able to connect with TCP. You can use Wireshark to capture packets and verify whether TCP or UDP is being used. In Chrome you can also see details on the selected candidate (
googActiveConnection
) by going tochrome://webrtc-internals
.
可靠性模式"大概指的是DataChannel的可靠性模式a>,可以配置为在可靠或不可靠模式下运行.DTLS 指的是当前可选的,但很快是交换加密密钥的默认方法(另一种不推荐使用的模式是 SDES).Firefox 仅支持 DTLS,因此对于浏览器互操作,您目前需要在 Chrome 中启用它.
"Reliability mode" probably refers to the reliability mode of the DataChannel, which can be configured to run in reliable or unreliable mode. DTLS refers to the currently optional, but soon to be default method of exchanging encryption keys (the other deprecated mode is SDES). Firefox only supports DTLS, so for browser interop, you'll currently need to enable it in Chrome.
RTCPeerConnection(媒体)将使用 TCP 或 UDP,而 DataChannel 使用 SCTP.Firefox 使用的 SCTP 实现是在 UDP 之上实现的:https://code.google.com/p/sctp-refimpl/.
The RTCPeerConnection (media) will use TCP or UDP, while the DataChannel uses SCTP. The SCTP implementation used by Firefox is implemented on top of UDP: https://code.google.com/p/sctp-refimpl/.
在使用 addIceCandidate
.通常,您不应该尝试强制使用传输,因为 WebRTC 只会做正确的事".浏览器不会限制 WebRTC 使用的 TCP 连接数超出 RTCPeerConnection 或 DataChannel 的任何限制(即,如果您可以有 10 个 PeerConnections,它们每个都可以毫无问题地使用 TCP).
It's possible to filter out TCP or UDP ICE candidates before adding them with addIceCandidate
. Generally, you should not try to force the transport used since WebRTC will just "do the right thing". The browser does not limit the number of TCP connections used by WebRTC beyond any limit on the RTCPeerConnection or DataChannel (i.e., if you can have 10 PeerConnections, they can each use TCP without any problem).
这篇关于WebRTC 使用 TCP 还是 UDP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!