Class SIPChannel
The SIPChannel abstract class encapsulates the common properties and methods required of a SIP channel. A SIP channel's primary responsibility is sending and receiving messages from the network.
Inheritance
Implements
Inherited Members
Namespace: SIPSorcery.SIP
Assembly: SIPSorcery.dll
Syntax
public abstract class SIPChannel : IDisposable
Constructors
| Improve this Doc View SourceSIPChannel()
Declaration
protected SIPChannel()
SIPChannel(Encoding, Encoding)
Declaration
protected SIPChannel(Encoding sipEncoding, Encoding sipBodyEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Encoding | sipEncoding | |
System.Text.Encoding | sipBodyEncoding |
Fields
| Improve this Doc View SourceClosed
Indicates whether close has been called on the SIP channel. Once closed a SIP channel can no longer be used to send or receive messages. It should generally only be called at the same time the SIP transport class using it is shutdown.
Declaration
protected bool Closed
Field Value
Type | Description |
---|---|
System.Boolean |
logger
Declaration
protected ILogger logger
Field Value
Type | Description |
---|---|
Microsoft.Extensions.Logging.ILogger |
SIPMessageReceived
The function delegate that will be called whenever a new SIP message is received on the SIP channel.
Declaration
public SIPMessageReceivedAsyncDelegate SIPMessageReceived
Field Value
Type | Description |
---|---|
SIPMessageReceivedAsyncDelegate |
Properties
| Improve this Doc View SourceID
A unique ID for the channel. Useful for ensuring a transmission can occur on a specific channel without having to match listening addresses.
Declaration
public string ID { get; protected set; }
Property Value
Type | Description |
---|---|
System.String |
InternetDefaultAddress
The local IP address this machine uses to communicate with the Internet.
Declaration
public static IPAddress InternetDefaultAddress { get; }
Property Value
Type | Description |
---|---|
System.Net.IPAddress |
IsReliable
If the underlying transport channel is reliable, such as TCP, this will be set to true.
Declaration
public bool IsReliable { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsSecure
If the underlying transport channel is using transport layer security (e.g. TLS or WSS) this will be set to true.
Declaration
public bool IsSecure { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ListeningEndPoint
The IP end point this channel is listening on. Note it can contain IPAddress.Any which means it can match multiple IP addresses.
Declaration
public IPEndPoint ListeningEndPoint { get; }
Property Value
Type | Description |
---|---|
System.Net.IPEndPoint |
ListeningIPAddress
The IP address the channel is listening on. Can be IPAddress.Any so cannot be used directly in SIP Headers, SIP URIs etc. Instead call GetContactURI and provide the destination address.
Declaration
public IPAddress ListeningIPAddress { get; protected set; }
Property Value
Type | Description |
---|---|
System.Net.IPAddress |
ListeningSIPEndPoint
The SIP end point this channel is listening on. Note it can contain IPAddress.Any which means it can match multiple IP addresses.
Declaration
public SIPEndPoint ListeningSIPEndPoint { get; }
Property Value
Type | Description |
---|---|
SIPEndPoint |
LocalIPAddresses
The list of IP addresses that this SIP channel is listening on. The only mechanism for a channel to have multiple addresses is if it's socket address is set to IPAddress.Any.
Declaration
public static List<IPAddress> LocalIPAddresses { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<System.Net.IPAddress> |
Port
The port that this SIP channel is listening on.
Declaration
public int Port { get; protected set; }
Property Value
Type | Description |
---|---|
System.Int32 |
SIPBodyEncoding
Declaration
public Encoding SIPBodyEncoding { get; }
Property Value
Type | Description |
---|---|
System.Text.Encoding |
SIPEncoding
Declaration
public Encoding SIPEncoding { get; }
Property Value
Type | Description |
---|---|
System.Text.Encoding |
SIPProtocol
The type of SIP protocol (udp, tcp, tls or web socket) for this channel.
Declaration
public SIPProtocolsEnum SIPProtocol { get; protected set; }
Property Value
Type | Description |
---|---|
SIPProtocolsEnum |
Methods
| Improve this Doc View SourceClose()
Closes the SIP channel. Closing stops the SIP channel from receiving or sending and typically should only be done at the same time the parent SIP transport layer is shutdown.
Declaration
public abstract void Close()
Dispose()
Calls close on the SIP channel when the object is disposed.
Declaration
public abstract void Dispose()
GetContactURI(SIPSchemesEnum, SIPEndPoint)
The contact SIP URI to be used for contacting this SIP channel WHEN sending to the destination IP address. The contact URI can change based on the destination. For example if the SIP channel is listening on IPAddress.Any a destination address of 127.0.0.1 will result in a contact of sip:127.0.0.1:X. Using the same channel to send to a destination address on the Internet will result in a different URI.
Declaration
public SIPURI GetContactURI(SIPSchemesEnum scheme, SIPEndPoint dstEndPoint)
Parameters
Type | Name | Description |
---|---|---|
SIPSchemesEnum | scheme | The SIP scheme to use for the Contact URI. |
SIPEndPoint | dstEndPoint | The destination SIP end point the Contact URI is for. For a SIPChannel using IPAddress.Any the destination needs to be known so it can select the correct local address. |
Returns
Type | Description |
---|---|
SIPURI |
GetLocalIPAddressForDestination(IPAddress)
Gets the local IP address this SIP channel will use for communicating with the destination IP address.
Declaration
protected IPAddress GetLocalIPAddressForDestination(IPAddress dst)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPAddress | dst | The destination IP address. |
Returns
Type | Description |
---|---|
System.Net.IPAddress | The local IP address this channel selects to use for connecting to the destination. |
HasConnection(SIPEndPoint)
Checks whether the SIP channel has an existing connection for a remote end point. Existing connections include connections that have been accepted by this channel's listener and connections that have been initiated due to sends from this channel.
Declaration
public abstract bool HasConnection(SIPEndPoint remoteEndPoint)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | remoteEndPoint | The remote end point to check for an existing connection. |
Returns
Type | Description |
---|---|
System.Boolean | True if a match is found or false if not. |
HasConnection(String)
Checks whether the SIP channel has a connection matching a unique connection ID.
Declaration
public abstract bool HasConnection(string connectionID)
Parameters
Type | Name | Description |
---|---|---|
System.String | connectionID | The connection ID to check for a match on. |
Returns
Type | Description |
---|---|
System.Boolean | True if a match is found or false if not. |
HasConnection(Uri)
Checks whether a web socket based SIP channel has an existing connection to a server URI.
Declaration
public abstract bool HasConnection(Uri serverUri)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | serverUri | The remote server URI to check for an existing connection. |
Returns
Type | Description |
---|---|
System.Boolean | True if a match is found or false if not. |
IsAddressFamilySupported(AddressFamily)
Returns true if the channel supports the requested address family.
Declaration
public abstract bool IsAddressFamilySupported(AddressFamily addresFamily)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Sockets.AddressFamily | addresFamily |
Returns
Type | Description |
---|---|
System.Boolean |
IsProtocolSupported(SIPProtocolsEnum)
Returns true if the channel supports the requested transport layer protocol.
Declaration
public abstract bool IsProtocolSupported(SIPProtocolsEnum protocol)
Parameters
Type | Name | Description |
---|---|---|
SIPProtocolsEnum | protocol |
Returns
Type | Description |
---|---|
System.Boolean |
SendAsync(SIPEndPoint, Byte[], Boolean, String)
Asynchronous SIP message send to a remote end point.
Declaration
public abstract Task<SocketError> SendAsync(SIPEndPoint dstEndPoint, byte[] buffer, bool canInitiateConnection, string connectionIDHint = null)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | dstEndPoint | The remote end point to send the message to. |
System.Byte[] | buffer | The data to send. |
System.Boolean | canInitiateConnection | Indicates whether this send should initiate a connection if needed. The typical case is SIP requests can initiate new connections but responses should not. Responses should only be sent on the same TCP or TLS connection that the original request was received on. |
System.String | connectionIDHint | Optional ID of the specific client connection that the message should be sent on. It's only a hint so if the connection has been closed a new one will be attempted. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> | If no errors SocketError.Success otherwise an error value. |
SendSecureAsync(SIPEndPoint, Byte[], String, Boolean, String)
Asynchronous SIP message send over a secure TLS connection to a remote end point.
Declaration
public abstract Task<SocketError> SendSecureAsync(SIPEndPoint dstEndPoint, byte[] buffer, string serverCertificateName, bool canInitiateConnection, string connectionIDHint = null)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | dstEndPoint | The remote end point to send the message to. |
System.Byte[] | buffer | The data to send. |
System.String | serverCertificateName | If the send is over SSL the required common name of the server's X509 certificate. |
System.Boolean | canInitiateConnection | Indicates whether this send should initiate a connection if needed. The typical case is SIP requests can initiate new connections but responses should not. Responses should only be sent on the same TCP or TLS connection that the original request was received on. |
System.String | connectionIDHint | Optional ID of the specific client connection that the message should be sent on. It's only a hint so if the connection has been closed a new one will be attempted. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> | If no errors SocketError.Success otherwise an error value. |