Does WebRTC use TCP or UDP?

50,659
  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).

Share:
50,659
onmyway133
Author by

onmyway133

I work with iOS, macOS, Android, React, Electron and Nodejs. I actively work on open source with 1.3k+ followers on GitHub, 45k+ apps touched and 3.4m+ downloads on CocoaPods. I also write on Medium with 2.3k+ followers with 90k+ monthly views. Support my apps https://onmyway133.com/apps Open source https://github.com/onmyway133 Writing https://medium.com/@onmyway133

Updated on December 08, 2020

Comments

  • onmyway133
    onmyway133 about 2 years

    This sounds like a very basic question, but I need a confirmation

    1. Does WebRTC use TCP or UDP as its peer-to-peer transport? How do I know ?
    2. I read that there are reliability mode and DTLS agreement, how does they affect?
    3. Is this transport the same for both Media and DataChannel?
    4. How do I switch between TCP and 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.

  • Sam Dutton
    Sam Dutton over 9 years
    Great answer! From Chrome 31, SCTP is used by default for data channels.
  • The Dembinski
    The Dembinski almost 6 years
    Rocking awesome answer. Thank you for the sources.
  • Pavel P
    Pavel P almost 4 years
    @Any reason SCTP isn't used by audio/video? Isn't it effectively udp with "extras" (currently it's implemented on top of udp mostly)
  • Thomas Orlita
    Thomas Orlita over 3 years
    For future users: in 1. chrome://webrtc-internals, you have to select "Read Stats From: Legacy"
  • Ben Butterworth
    Ben Butterworth over 2 years
    The reason why I personally asked the question "does WebRTC use TCP or UDP" is to see if it were reliable or not. Point 3 says, Media will use TCP or UDP, but DataChannel will use SCTP, so DataChannel should be reliable, because SCTP is reliable (according to the SCTP RFC). This contradicts point 2., so if someone could clarify great!