Class SIPTCPChannel
SIP transport for TCP. Note this is also the base class for the SIPTLSChannel. For the TLS channel the TCP base class will accept or connect and then switch to the TLS class to upgrade to an SSL stream.
Implements
Inherited Members
Namespace: SIPSorcery.SIP
Assembly: SIPSorcery.dll
Syntax
public class SIPTCPChannel : SIPChannel, IDisposable
Constructors
| Improve this Doc View SourceSIPTCPChannel(IPAddress, Int32, Boolean)
Declaration
public SIPTCPChannel(IPAddress listenAddress, int listenPort, bool useDualMode = false)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPAddress | listenAddress | |
System.Int32 | listenPort | |
System.Boolean | useDualMode |
SIPTCPChannel(IPEndPoint, SIPProtocolsEnum, Boolean, Boolean)
Declaration
public SIPTCPChannel(IPEndPoint endPoint, SIPProtocolsEnum protocol, bool canListen = true, bool useDualMode = false)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPEndPoint | endPoint | |
SIPProtocolsEnum | protocol | |
System.Boolean | canListen | |
System.Boolean | useDualMode |
SIPTCPChannel(IPEndPoint, SIPProtocolsEnum, Encoding, Encoding, Boolean, Boolean)
Creates a SIP channel to listen for and send SIP messages over TCP.
Declaration
public SIPTCPChannel(IPEndPoint endPoint, SIPProtocolsEnum protocol, Encoding sipEncoding, Encoding sipBodyEncoding, bool canListen, bool useDualMode)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPEndPoint | endPoint | The IP end point to send from and optionally listen on. |
SIPProtocolsEnum | protocol | Whether the channel is being used with TCP or TLS (TLS channels get upgraded once connected). |
System.Text.Encoding | sipEncoding | |
System.Text.Encoding | sipBodyEncoding | |
System.Boolean | canListen | Indicates whether the channel is capable of listening for new client connections. A TLS channel without a certificate cannot listen. |
System.Boolean | useDualMode |
SIPTCPChannel(IPEndPoint, Boolean)
Declaration
public SIPTCPChannel(IPEndPoint endPoint, bool useDualMode = false)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPEndPoint | endPoint | |
System.Boolean | useDualMode |
SIPTCPChannel(IPEndPoint, Encoding, Encoding, Boolean)
Declaration
public SIPTCPChannel(IPEndPoint endPoint, Encoding sipEncoding, Encoding sipBodyEncoding, bool useDualMode = false)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IPEndPoint | endPoint | |
System.Text.Encoding | sipEncoding | |
System.Text.Encoding | sipBodyEncoding | |
System.Boolean | useDualMode |
Fields
| Improve this Doc View SourceDisableLocalTCPSocketsCheck
Can be set to allow TCP channels hosted in the same process to send to each other. Useful for testing. By default sends between TCP channels in the same process are disabled to prevent resource exhaustion.
Declaration
public bool DisableLocalTCPSocketsCheck
Field Value
Type | Description |
---|---|
System.Boolean |
m_channelSocket
This is the main object managed by this class. It is the socket listening for incoming connections.
Declaration
protected Socket m_channelSocket
Field Value
Type | Description |
---|---|
System.Net.Sockets.Socket |
m_connectingSockets
List of sockets that are in the process of being connected to. Needed to avoid SIP re-transmits initiating multiple connect attempts.
Declaration
protected List<string> m_connectingSockets
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
Properties
| Improve this Doc View SourceProtDescr
This string is used in debug messages. It makes it possible to differentiate whether an instance in acting solely as a TCP channel or as the base class of a TLS channel.
Declaration
protected virtual string ProtDescr { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceClose()
Closes the channel and any open sockets.
Declaration
public override void Close()
Overrides
| Improve this Doc View SourceDispose()
Declaration
public override void Dispose()
Overrides
| Improve this Doc View SourceHasConnection(SIPEndPoint)
Checks whether there is 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 override 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 there is a connection or false if not. |
Overrides
| Improve this Doc View SourceHasConnection(String)
Checks whether the SIP channel has a connection matching a unique connection ID.
Declaration
public override 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. |
Overrides
| Improve this Doc View SourceHasConnection(Uri)
Not implemented for the TCP channel.
Declaration
public override bool HasConnection(Uri serverUri)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | serverUri |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
| Improve this Doc View SourceIsAddressFamilySupported(AddressFamily)
Checks whether the specified address family is supported.
Declaration
public override bool IsAddressFamilySupported(AddressFamily addresFamily)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Sockets.AddressFamily | addresFamily | The address family to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if supported, false if not. |
Overrides
| Improve this Doc View SourceIsProtocolSupported(SIPProtocolsEnum)
Checks whether the specified protocol is supported.
Declaration
public override bool IsProtocolSupported(SIPProtocolsEnum protocol)
Parameters
Type | Name | Description |
---|---|---|
SIPProtocolsEnum | protocol | The protocol to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if supported, false if not. |
Overrides
| Improve this Doc View SourceOnAccept(SIPStreamConnection)
For TCP channel no special action is required when accepting a new client connection. Can start receiving immediately.
Declaration
protected virtual void OnAccept(SIPStreamConnection streamConnection)
Parameters
Type | Name | Description |
---|---|---|
SIPStreamConnection | streamConnection | The stream connection holding the newly accepted client socket. |
OnClientConnect(SIPStreamConnection, String)
For TCP channel no special action is required when a new outgoing client connection is established. Can start receiving immediately.
Declaration
protected virtual Task<SocketError> OnClientConnect(SIPStreamConnection streamConnection, string certificateName)
Parameters
Type | Name | Description |
---|---|---|
SIPStreamConnection | streamConnection | The stream connection holding the newly connected client socket. |
System.String | certificateName |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> |
OnSIPStreamDisconnected(SIPStreamConnection, SocketError)
Event handler for a reliable SIP stream socket being disconnected.
Declaration
protected void OnSIPStreamDisconnected(SIPStreamConnection connection, SocketError socketError)
Parameters
Type | Name | Description |
---|---|---|
SIPStreamConnection | connection | The disconnected stream. |
System.Net.Sockets.SocketError | socketError | The cause of the disconnect. |
SendAsync(SIPEndPoint, Byte[], Boolean, String)
Declaration
public override Task<SocketError> SendAsync(SIPEndPoint dstEndPoint, byte[] buffer, bool canInitiateConnection, string connectionIDHint)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | dstEndPoint | |
System.Byte[] | buffer | |
System.Boolean | canInitiateConnection | |
System.String | connectionIDHint |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> |
Overrides
| Improve this Doc View SourceSendOnConnected(SIPStreamConnection, Byte[])
Sends data once the stream is connected. Can be overridden in sub classes that need to implement a different mechanism to send. For example SSL connections.
Declaration
protected virtual Task SendOnConnected(SIPStreamConnection sipStreamConn, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
SIPStreamConnection | sipStreamConn | The connected SIP stream wrapping the TCP connection. |
System.Byte[] | buffer | The data to send. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
SendSecureAsync(SIPEndPoint, Byte[], String, Boolean, String)
Attempts to send data to the remote end point over a reliable connection. If an existing connection exists it will be used otherwise an attempt will be made to establish a new connection.
Declaration
public override Task<SocketError> SendSecureAsync(SIPEndPoint dstSIPEndPoint, byte[] buffer, string serverCertificateName, bool canInitiateConnection, string connectionIDHint)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | dstSIPEndPoint | The remote SIP end point to send the reliable data to. |
System.Byte[] | buffer | The data to send. |
System.String | serverCertificateName | Optional. Only relevant for SSL streams. The common name that is expected for the remote SSL server. |
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. The ID of the specific TCP connection to try and the send the message on. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> | If no errors SocketError.Success otherwise an error value. |
Overrides
| Improve this Doc View SourceSIPTCPMessageReceived(SIPChannel, SIPEndPoint, SIPEndPoint, Byte[])
Gets fired when a suspected SIP message is extracted from the TCP data stream.
Declaration
protected Task SIPTCPMessageReceived(SIPChannel channel, SIPEndPoint localEndPoint, SIPEndPoint remoteEndPoint, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
SIPChannel | channel | |
SIPEndPoint | localEndPoint | |
SIPEndPoint | remoteEndPoint | |
System.Byte[] | buffer |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |