# mediasop 3.14.0 has been released with portRange in TransportListenInfo

**URL:** <https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976>\
**Category:** Announcements\
**Created:** [April 8, 2024, 2:54pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976 "2024-04-08T14:54:16Z")\
**Posts on this page:** 11\
**Page:** 1

<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:** [April 8, 2024, 2:54pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/1 "2024-04-08T14:54:16Z")

</div>

Hi, mediasop 3.14.0 has been released with `portRange` in `TransportListenInfo`.

### Details

- New optional `portRange` field of type [`TransportPortRange`](https://mediasoup.org/documentation/v3/mediasoup/api/#TransportPortRange) has been added in [`TransportListenInfo`](https://mediasoup.org/documentation/v3/mediasoup/api/#TransportListenInfo), so it’s available in `router.createWebRtcTransport()`, `router.createPlainTransport()`, `router.createPipeTransport()` and `worker.createWebRtcServer()` methods.

- If `portRange` is given, then a free random port in that range (and given `ip` and `protocol`) will be chosen.

- This feature deprecates worker ports range (`rtcMinPort` and `rtcMaxPort` in `WorkerSettings` given to `createWorker()` method). Rationale is that it doesn’t make any sense to have a unique port range for different listening IPs (for example: an app may want to use different port ranges for public connections (public internet) and private connections (private network).

- Here the corresponding PR: [https://github.com/versatica/mediasoup/pull/1365](https://github.com/versatica/mediasoup/pull/1365)

- **Bonus track:** Node \>= 18 is required (so mediasoup no longer runs in Node 16).

---

<div class="post-metadata">

**Author:** ![miroslavpejic85](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/miroslavpejic85/32/1044_2.png) [@miroslavpejic85](https://mediasoup.discourse.group/u/miroslavpejic85)\
**Post date:** [April 8, 2024, 3:46pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/2 "2024-04-08T15:46:30Z")

</div>

Nice, make sense, thank you!

Just a few questions:

1. Regarding `webRtcTransportOptions`, can the same `portRange` be used for both UDP and TCP `listenInfos`, or must they be different ranges?

```auto
    webRtcTransportOptions {
       listenInfos: [
           { protocol: 'udp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 40000, max: 40100 }},
           { protocol: 'tcp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 40000, max: 40100 }},
       ],
   }

```

1. For configuring the `webRtcServer`, are both of these configurations valid?

2. If the `WebRtcServer` is designed to work with a single port per worker (without need to open large ports range in the firewall), why would someone need to use a portRange in this case?

---

<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:** [April 8, 2024, 4:31pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/3 "2024-04-08T16:31:19Z")

</div>

> [@miroslavpejic85](#):
>
> 1. Regarding `webRtcTransportOptions`, can the same `portRange` be used for both UDP and TCP `listenInfos`, or must they be different ranges?

Why should they be different? 😀

> [@miroslavpejic85](#):
>
> For configuring the `webRtcServer`, are both of these configurations valid?
> 
> a. Using a single port:
> 
> ```auto
> webRtcServerOptions: {
> listenInfos: [
> { protocol: 'udp', ip: '0.0.0.0', announcedAddress: IPv4, port: 44444 },
> { protocol: 'tcp', ip: '0.0.0.0', announcedAddress: IPv4, port: 44444 },
> ],
> },
> 
> ```
> 
> b. Using a portRange:
> 
> ```auto
> webRtcServerOptions: {
> listenInfos: [
> { protocol: 'udp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 44444, max: 44444 } },
> { protocol: 'tcp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 44444, max: 44444 } },
> 
> ```

As per the documentation both approaches do the same.

> [@miroslavpejic85](#):
>
> 1. If the `WebRtcServer` is designed to work with a single port per worker (without need to open large ports range in the firewall), why would someone need to use a portRange in this case?

When creating many workers, each one with its own `WebRtcServer`.

---

<div class="post-metadata">

**Author:** ![miroslavpejic85](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/miroslavpejic85/32/1044_2.png) [@miroslavpejic85](https://mediasoup.discourse.group/u/miroslavpejic85)\
**Post date:** [April 8, 2024, 4:51pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/4 "2024-04-08T16:51:56Z")

</div>

> [@ibc](#):
>
> When creating many workers, each one with its own `WebRtcServer`.

Yeah, got it, but why would one choose to specify a `portRange` in the `ListenInfos` of a `WebRtcServer` when typically a `single port` should be `sufficient`, especially in scenarios involving multiple workers each with its own `WebRtcServer`?

Edit: Maybe for Load Distribution: By defining a range of ports rather than just one, the `WebRtcServer` gains the ability to distribute incoming connections across multiple ports. This can help in balancing the load more efficiently, especially in high-traffic environments.

---

<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:** [April 8, 2024, 5:01pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/5 "2024-04-08T17:01:52Z")

</div>

> [@miroslavpejic85](#):
>
> Yeah, got it, but why would one choose to specify a `portRange` in the `ListenInfos` of a `WebRtcServer` when typically a `single port` should be `sufficient`, especially in scenarios involving multiple workers each with its own `WebRtcServer`?

- You have ports 20001-20008 open in your host.
- You create 8 workers and in each worker you create a `WebRtcServer` with `portRange: { min: 20001, max: 20008 }`.
- All ports will be used and you don’t need to care about assigning fixed ports.

> [@miroslavpejic85](#):
>
> Edit: Maybe for Load Distribution: By defining a range of ports rather than just one, the `WebRtcServer` gains the ability to distribute incoming connections across multiple ports. This can help in balancing the load more efficiently, especially in high-traffic environments.

Not sure what you mean. `portRange` is not about opening many ports. It’s about opening a **single** port in the given port range. Which one? Any available random port.

---

<div class="post-metadata">

**Author:** ![zaidiqbal](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/zaidiqbal/32/1498_2.png) [@zaidiqbal](https://mediasoup.discourse.group/u/zaidiqbal)\
**Post date:** [April 8, 2024, 5:10pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/6 "2024-04-08T17:10:59Z")

</div>

> [@ibc](#):
>
> - You have ports 20001-20008 open in your host.
> - You create 8 workers and in each worker you create a `WebRtcServer` with `portRange: { min: 20001, max: 20008 }`.
> - All ports will be used and you don’t need to care about assigning fixed ports.

hi, If one port is given instead of port range then only that port will be used by all workers, and mediasoup will not have any issues dealing the packet with that single port?

---

<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:** [April 8, 2024, 5:17pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/7 "2024-04-08T17:17:05Z")

</div>

As the documentation says two workers cannot listen in same port.

---

<div class="post-metadata">

**Author:** ![miroslavpejic85](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/miroslavpejic85/32/1044_2.png) [@miroslavpejic85](https://mediasoup.discourse.group/u/miroslavpejic85)\
**Post date:** [April 8, 2024, 5:32pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/8 "2024-04-08T17:32:42Z")

</div>

> [@ibc](#):
>
> - You have ports 20001-20008 open in your host.
> - You create 8 workers and in each worker you create a `WebRtcServer` with `portRange: { min: 20001, max: 20008 }`.
> - All ports will be used and you don’t need to care about assigning fixed ports.

Thank you for the explanation 😉

Perhaps it’s necessary to also revisit **[this section](https://github.com/versatica/mediasoup-demo/blob/cfe014a77ac596fd68071700e4d99120ba7ade93/server/server.js#L132)** in the mediasoup demo. Here, it appears that ports are being allocated dynamically without consideration for whether the `portRange` is set in the `WebRtcServerOption listenInfos`.

Below is a suggested improvement:

```js
if (!listenInfo.portRange) 
{ 
   listenInfo.port += portIncrement;
}

```

---

<div class="post-metadata">

**Author:** ![miroslavpejic85](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/miroslavpejic85/32/1044_2.png) [@miroslavpejic85](https://mediasoup.discourse.group/u/miroslavpejic85)\
**Post date:** [April 8, 2024, 5:56pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/9 "2024-04-08T17:56:25Z")

</div>

> [@ibc](#):
>
> Not sure what you mean. `portRange` is not about opening many ports. It’s about opening a **single** port in the given port range. Which one? Any available random port.

Thanks, everything is clearer to me now.

---

<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:** [April 9, 2024, 7:47am UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/10 "2024-04-09T07:47:04Z")

</div>

> [@miroslavpejic85](#):
>
> Below is a suggested improvement:
> 
> ```auto
> if (!listenInfo.portRange) 
> { 
> listenInfo.port += portIncrement;
> }
> 
> ```

In config.js we don’t pass any `portRange` to `WebRtcServer` but a single `port`. I understand your point but honestly nobody should take mediasoup-demo as a reference app.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mediasoup/original/2X/b/b318c4d3397e65af9535f79c605b80b9ceb066c8.png) [@system](https://mediasoup.discourse.group/u/system)\
**Post date:** [April 10, 2024, 2:54pm UTC](https://mediasoup.discourse.group/t/mediasop-3-14-0-has-been-released-with-portrange-in-transportlisteninfo/5976/11 "2024-04-10T14:54:28Z")

</div>

This topic was automatically closed after 2 days. New replies are no longer allowed.
