# STUN / TURN server

**URL:** <https://mediasoup.discourse.group/t/stun-turn-server/1775>\
**Category:** Integration\
**Created:** [September 20, 2020, 2:10pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775 "2020-09-20T14:10:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Athina635](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/athina635/32/544_2.png) [@Athina635](https://mediasoup.discourse.group/u/Athina635)\
**Post date:** [September 20, 2020, 2:10pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/1 "2020-09-20T14:10:06Z")

</div>

Hello,

I was working with peer to peer technology before and in the production mode i needed to configure the **iceServers: []** that contain a **Stun** and **Turn** servers to ensure best connectivity between peers.

do i need to use this **iceServers** in the Mediasoup use case ?

if yes, please, where could i integrate my servers? **(stun/turn iceServers: [])**

---

<div class="post-metadata">

**Author:** ![Dirvann](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/dirvann/32/419_2.png) [@Dirvann](https://mediasoup.discourse.group/u/Dirvann)\
**Post date:** [September 21, 2020, 9:54pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/2 "2020-09-21T21:54:40Z")

</div>

As far as I know you don’t need any.  
Stun servers are used to find the ip of the two parties to try to have a direct connection. With mediasoup you already know the IP of your server so the browser knows exactly where to connect to.  
Turn servers are used as a relay if direct connection isn’t possible. With mediasoup you already have a direct connection to the server from the browser.

---

<div class="post-metadata">

**Author:** ![Athina635](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/athina635/32/544_2.png) [@Athina635](https://mediasoup.discourse.group/u/Athina635)\
**Post date:** [September 21, 2020, 10:01pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/3 "2020-09-21T22:01:42Z")

</div>

@Dirvann I Got you now and the answer was on my question, I was using a peer to peer tech.  
Thank you so much.

good job in the Github.

---

<div class="post-metadata">

**Author:** ![Athina635](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/athina635/32/544_2.png) [@Athina635](https://mediasoup.discourse.group/u/Athina635)\
**Post date:** [October 5, 2020, 2:52pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/4 "2020-10-05T14:52:08Z")

</div>

no more available ports [transport:udp, ip:’0.0.0.0’, numAttempt:101](https://mediasoup.discourse.group/t/no-more-available-ports-transport-udp-ip-0-0-0-0-numattempt-101/1843) what does it mean ? i notice that frequence error many times when i tested the library? is that mean the server reacht he max consumer and producer number ?

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [October 5, 2020, 2:57pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/5 "2020-10-05T14:57:37Z")

</div>

It means that:

1. You are not closing mediasoup `Transports` once their clients disconnect, or
2. You are not opening enough ports.

This is a bug in your app logic/code.

---

<div class="post-metadata">

**Author:** ![Athina635](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/athina635/32/544_2.png) [@Athina635](https://mediasoup.discourse.group/u/Athina635)\
**Post date:** [October 5, 2020, 7:27pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/6 "2020-10-05T19:27:55Z")

</div>

hello, how can I know the total number of producers and consumers on my server or on my mediasoup extention ?

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [October 5, 2020, 7:33pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/7 "2020-10-05T19:33:21Z")

</div>

You create them so you must know.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [October 5, 2020, 7:33pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/8 "2020-10-05T19:33:39Z")

</div>

Also please don’t use an existing thread for unrelated questions.

---

<div class="post-metadata">

**Author:** ![footniko](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/footniko/32/79_2.png) [@footniko](https://mediasoup.discourse.group/u/footniko)\
**Post date:** [October 25, 2020, 7:37pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/9 "2020-10-25T19:37:02Z")

</div>

If a client has blocked UDP ports, TURN server comes to the rescue, so data would be sent through TCP, with a bigger delay ofc, but it covers more clients.

---

<div class="post-metadata">

**Author:** ![tallguy](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@tallguy](https://mediasoup.discourse.group/u/tallguy)\
**Post date:** [November 25, 2020, 6:19pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/10 "2020-11-25T18:19:22Z")

</div>

I found this thread and comments from @ibc very helpful regarding STUN/TURN:  
[https://groups.google.com/g/mediasoup/c/CwsxtmCcrh4/m/puOJlEDLBwAJ](https://groups.google.com/g/mediasoup/c/CwsxtmCcrh4/m/puOJlEDLBwAJ)

In many of the historical posts from @ibc he pointed out that MediaSoup uses ICE-LITE, “meaning that it does not require ICE candidates from clients but, instead, will wait for RTP in its open ports to know the client’s remote IP, port and transport protocol (UDP or TCP).”

Another thing I have read that may be useful here: configuration using port 443 is a way to get around restrictive corporate firewalls, if necessary. From @ibc in [this post](https://mediasoup.discourse.group/t/improving-video-connection-success-rate/212/2):

> For worst network cases you should have your TURN server listening into TLS port 443 with a proper TLS certificate. Since some networks (WiFi in hotels and so on) block traffic other than 80 and 443, you’d rather have TURN listening in TLS 443 of public IP\_A and your HTTP/WS signaling server in TLS 443 of public IP\_B.

One thing I am also investigating, rather than eliminate stun/turn entirely, is if there is any benefit to installing Coturn alongside MediaSoup, even on the same server, and using it for normalizing client connections and managing them and then MediaSoup for the SFU functions. This and port 443 is mentioned in a post at medium (google: WebRTC pro-tips @ Medium – I am limited in links in my post as a new member)

> If you’re using an SFU or MCU, consider running TURN along-side your software, and forcing everyone to relay through TURN. It’s sixes this way and can actually simplify a few things.

---

<div class="post-metadata">

**Author:** ![jamesjessian](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jamesjessian/32/525_2.png) [@jamesjessian](https://mediasoup.discourse.group/u/jamesjessian)\
**Post date:** [February 11, 2021, 2:25pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/11 "2021-02-11T14:25:24Z")

</div>

HI, just wondering if have managed to implement a TURN server between your mediasoup client and mediasoup server?  
We currently use Jitsi as a video conferencing platform but wanted to evaluate/compare with mediasoup. We have coturn running on the same 443 port on the server as the web client itself (but with a different domain name and cert).  
I can’t seem to find any direct experiences on using a TURN server with mediasoup yet, or how it would be implemented without further WebRTC knowledge from other sources. We have clients behind corporate firewalls that mean we have to use a TURN server on a TCP:443 port.  
I presume we’d need a coturn server listening on port 443 and we’d provide that to the mediasoup client using _transport.updateIceServers_([])

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [February 11, 2021, 3:27pm UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/12 "2021-02-11T15:27:31Z")

</div>

mediasoup (server) does not need any knowledge/configuration related to TURN. You must setup your TURN server so it has proper direct networking to the mediasoup server. That’s all.

In client side you pass STUN/TURN servers when creating a send/recv transport:

> **[mediasoup :: API](https://mediasoup.org/documentation/v3/mediasoup-client/api/#TransportOptions)**
>
> Cutting Edge WebRTC Video Conferencing

---

<div class="post-metadata">

**Author:** ![jamesjessian](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/jamesjessian/32/525_2.png) [@jamesjessian](https://mediasoup.discourse.group/u/jamesjessian)\
**Post date:** [February 12, 2021, 11:10am UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/13 "2021-02-12T11:10:13Z")

</div>

Thanks @ibc, I will try it. Can I also confirm that the client will only use the TURN server other (e.g. UDP) communication isn’t availble? As a failover. I’m not sure if that would be based on logic in the mediasoup client or underlying libraries.  
And we can have some clients using the TURN server, and others not using it, in the same conference? Presumably, like you say, the clients/server would not know or care.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [February 12, 2021, 11:51am UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/14 "2021-02-12T11:51:58Z")

</div>

Each client will choose whether to use TURN or not depending on previous ICE process and on what it feels works better.

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [February 12, 2021, 11:52am UTC](https://mediasoup.discourse.group/t/stun-turn-server/1775/15 "2021-02-12T11:52:28Z")

</div>

And this is PeerConnection behavior, mediasoup-client does decide here.
