Class PortRange
Class to manage port allocation for Rtp Ports. Ports are always even, because due Rtp data and control ports are always with data on even port and control (if any) on data_port + 1
There are two operation modes:
- The sequential mode which hands out all ports within the assigned range and wraps around if the last port was assigned
- The shuffled mode: Ports are handed out evenly distributed within the assigned port range.
Inheritance
Inherited Members
Namespace: SIPSorcery.Sys
Assembly: SIPSorcery.dll
Syntax
public class PortRange
Constructors
| Improve this Doc View SourcePortRange(Int32, Int32, Boolean, Nullable<Int32>)
Initializes a new PortRange.
Declaration
public PortRange(int startPort, int endPort, bool shuffle = false, int? randomSeed = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPort | Inclusive, lowest port within this portrange. must be an even number |
System.Int32 | endPort | Inclusive, highest port within this portrange. |
System.Boolean | shuffle | optional, if set, the ports are assigned in a pseudorandom order. |
System.Nullable<System.Int32> | randomSeed | optional, the seed for the pseudorandom order. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
Fields
| Improve this Doc View SourceEndPort
Declaration
public readonly int EndPort
Field Value
Type | Description |
---|---|
System.Int32 |
StartPort
Declaration
public readonly int StartPort
Field Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceGetNextPort()
Calculates the next port which should be tried. No guarantee is made, that the returned port can also be bound to; actual check is still needed. Caller of this method should try to bind to the socket and if not successful, try again for x times before giving up.
This method is thread-safe
Declaration
public virtual int GetNextPort()
Returns
Type | Description |
---|---|
System.Int32 | port from the portrange |