WebRTC 使用 TCP 还是 UDP?

我有一些关于 WebRTC 的问题:

  1. WebRTC 是否使用 TCP 或 UDP 作为其对等传输 知道吗?
  2. 我看到有可靠性模式和 DTLS 协议,怎么办 这些影响?
  3. Media 和 DataChannel 的传输方式是否相同?
  4. 如何在 TCP 和 UDP 之间切换?

我这样问是因为我知道浏览器对并行连接的数量有限制(我认为它们是通过 TCP 进行通信的) ,也许 UDP 连接是不受限制的。

56929 次浏览
  1. 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 to chrome://webrtc-internals.

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

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

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