Search code examples
webrtcstunturncoturn

How many WebRTC connections are there in TURN server?


I am trying out WebRTC and would like to find out more about how TURN server works, in terms of connections.

Because I have tried that even mobile devices with same telco, they are not able to connect to each other directly. A TURN server is required to relay the messages.

Assuming a room has 4 players A,B,C,D and all are NOT able to connect to each other directly. So for the TURN server, how many connections are there?

a) 6 b) 12 or more?

In the case of a peer broadcasting to other peers, how many messages will be received and relayed by the TURN server?


Solution

  • There will be n×(n-1) connections. Each peer sends a stream to all other peers. In the case of two peers, that's one stream per peer, two streams in total. For four peers, that's three streams per peer for 12 streams in total.

    Assuming that no peer can connection directly, they all have to be routed through a TURN server.

    A TURN server is a "dumb" relay, it merely relays the stream as is and leaves all the logic and stream processing to the clients. So each client will have to separately encode three different streams to send to three different peers.

    To have something more efficient, you need a media server like the popular Kurento, which can take one stream and redistribute ("broadcast") it to multiple individual clients. I.e. it takes on the logic and stream processing task. This requires more complicated setup and a beefier server than TURN though. In practice, you'll probably want to pay a SaaS provider for this than setting up your own.