Class TcpSocket
A TCP socket.
Inherited Members
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public class TcpSocket : StreamSocket
Constructors
TcpSocket(Boolean, Boolean, Boolean)
Initializes a new instance of the TcpSocket class.
Declaration
public TcpSocket(bool server, bool ipv6, bool secure)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | server | Whether the socket is going to accept new incoming connections. |
System.Boolean | ipv6 | Whether an IPv6 socket should be created. |
System.Boolean | secure | Whether to send data securely using SSL. |
TcpSocket(Socket, Boolean, Boolean)
Initializes a new instance of the TcpSocket class.
Declaration
public TcpSocket(Socket socket, bool server, bool secure)
Parameters
Type | Name | Description |
---|---|---|
System.Net.Sockets.Socket | socket | The existing socket. |
System.Boolean | server | Whether the socket is server-side. |
System.Boolean | secure | Whether the socket is secure. |
Properties
AttemptIPv4Dscp
Attempt to use DSCP for IPv4 when possible. Default is false. You must "opt-in".
Declaration
public static bool AttemptIPv4Dscp { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
AttemptIPv6Dscp
Attempt to use DSCP for IPv6 when possible. Default is false. You must "opt-in".
Declaration
public static bool AttemptIPv6Dscp { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
AttemptNoDelay
Attempt to set the Socket NoDelay
property to disable Nagling. Default is false. You must "opt-in".
Declaration
public static bool AttemptNoDelay { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Certificate
Gets or sets the certificate to use to secure the socket. This is required for secure server sockets.
Declaration
public static X509Certificate2 Certificate { get; set; }
Property Value
Type | Description |
---|---|
System.Security.Cryptography.X509Certificates.X509Certificate2 |
ClientEnabledSslProtocols
Gets or sets the client-side enabled SSL protocols.
If null
, the client socket will default to TLS 1.0, 1.1, and 1.2.
Declaration
public static SslProtocols? ClientEnabledSslProtocols { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Security.Authentication.SslProtocols> |
ClientSslAuthenticate
Gets or sets the function to authenticate an SSL stream as a client. Defaults to using SslStream.AuthenticateAsClient without client certificates or checking certificate revocation.
Declaration
public static TcpSocket.ClientSslAuthenticateDelegate ClientSslAuthenticate { get; set; }
Property Value
Type | Description |
---|---|
TcpSocket.ClientSslAuthenticateDelegate |
ClientSslValidateServerCertificate
Gets or sets the function to validate an SSL server certificate as a client.
Declaration
public static TcpSocket.ClientSslValidateServerCertificateDelegate ClientSslValidateServerCertificate { get; set; }
Property Value
Type | Description |
---|---|
TcpSocket.ClientSslValidateServerCertificateDelegate |
DisableProxy
Gets or sets whether the system proxy should be disabled.
Declaration
public static bool DisableProxy { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
EnabledSslProtocols
Gets or sets the enabled SSL protocols.
Declaration
public SslProtocols? EnabledSslProtocols { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Security.Authentication.SslProtocols> |
IPv6
Gets a value indicating whether the socket supports IPv6.
Declaration
public override bool IPv6 { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
IsClosed
Gets a value indicating whether this instance is closed.
Declaration
public override bool IsClosed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
ListenBacklog
Gets or sets the maximum length of the pending connections queue.
Declaration
public int ListenBacklog { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
LocalIPAddress
Gets the local IP address.
Declaration
public override string LocalIPAddress { get; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
LocalPort
Gets the local port.
Declaration
public override int LocalPort { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
ManualProxyHostname
Gets or sets the manual proxy hostname, which overrides system settings.
Declaration
public static string ManualProxyHostname { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ManualProxyPort
Gets or sets the manual proxy proxy, which overrides system settings.
Declaration
public static int ManualProxyPort { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
ProxyIPAddress
Gets or sets the proxy IP address.
Declaration
public string ProxyIPAddress { get; }
Property Value
Type | Description |
---|---|
System.String |
ProxyPassword
Gets or sets the proxy password, if the proxy requires a username.
Declaration
public static string ProxyPassword { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ProxyPort
Gets or sets the proxy port.
Declaration
public int ProxyPort { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ProxyUsername
Gets or sets the proxy username, if the proxy requires a username.
Declaration
public static string ProxyUsername { get; set; }
Property Value
Type | Description |
---|---|
System.String |
RemoteHostname
Gets the remote hostname.
Declaration
public override string RemoteHostname { get; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
RemoteIPAddress
Gets the remote IP address.
Declaration
public override string RemoteIPAddress { get; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
RemotePort
Gets the remote port.
Declaration
public override int RemotePort { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
Secure
Gets a value indicating whether the socket is secure.
Declaration
public override bool Secure { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
Server
Gets a value indicating whether the socket can accept incoming connections.
Declaration
public override bool Server { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
ServerEnabledSslProtocols
Gets or sets the server-side enabled SSL protocols.
If null
, the server socket will default to TLS 1.2.
Declaration
public static SslProtocols? ServerEnabledSslProtocols { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Security.Authentication.SslProtocols> |
ServerSslAuthenticate
Gets or sets the function to authenticate an SSL stream as a server. Defaults to using SslStream.AuthenticateAsServer without requiring a client certificate or checking certificate revocation.
Declaration
public static TcpSocket.ServerSslAuthenticateDelegate ServerSslAuthenticate { get; set; }
Property Value
Type | Description |
---|---|
TcpSocket.ServerSslAuthenticateDelegate |
Socket
Gets the underlying socket.
Declaration
public Socket Socket { get; }
Property Value
Type | Description |
---|---|
System.Net.Sockets.Socket |
Stream
Gets the underlying stream.
Declaration
public Stream Stream { get; }
Property Value
Type | Description |
---|---|
System.IO.Stream |
Methods
AcceptAsync(Action0, Action1<Exception>, Action1<StreamSocket>)
Accepts a new socket asynchronously.
Declaration
public override void AcceptAsync(Action0 onSuccess, Action1<Exception> onFailure, Action1<StreamSocket> onSocket)
Parameters
Type | Name | Description |
---|---|---|
Action0 | onSuccess | The callback to invoke on success. |
Action1<System.Exception> | onFailure | The callback to invoke on failure. |
Action1<StreamSocket> | onSocket | The callback to invoke when a socket is ready. |
Overrides
AcceptAsync(Action0, Action1<Exception>, Action1<StreamSocket>, Action1<Exception>)
Accepts a new socket asynchronously.
Declaration
public void AcceptAsync(Action0 onSuccess, Action1<Exception> onFailure, Action1<StreamSocket> onSocket, Action1<Exception> onSocketFailure)
Parameters
Type | Name | Description |
---|---|---|
Action0 | onSuccess | The callback to invoke on success. |
Action1<System.Exception> | onFailure | The callback to invoke on failure. |
Action1<StreamSocket> | onSocket | The callback to invoke when a socket is ready. |
Action1<System.Exception> | onSocketFailure | The callback to invoke when a socket fails to become ready. |
Bind(String, Int32, out Boolean)
Binds the socket to a local endpoint.
Declaration
public override bool Bind(string ipAddress, int port, out bool addressInUse)
Parameters
Type | Name | Description |
---|---|---|
System.String | ipAddress | The local IP address. |
System.Int32 | port | The local port. |
System.Boolean | addressInUse | Indicates that access to the address is forbidden or in use. |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Close()
Closes the socket.
Declaration
public override void Close()
Overrides
ConnectAsync(String, String, Int32, Int32, Action0, Action2<Exception, Boolean>)
Connects the socket asynchronously.
Declaration
public override void ConnectAsync(string hostname, string ipAddress, int port, int timeout, Action0 onSuccess, Action2<Exception, bool> onFailure)
Parameters
Type | Name | Description |
---|---|---|
System.String | hostname | The remote hostname. |
System.String | ipAddress | The remote IP address. |
System.Int32 | port | The remote port. |
System.Int32 | timeout | The timeout (in ms). |
Action0 | onSuccess | The callback to invoke on success. |
Action2<System.Exception, System.Boolean> | onFailure | The callback to invoke on failure. |
Overrides
ReceiveAsync(Int32)
Receives data asynchronously.
Declaration
public override void ReceiveAsync(int timeout)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | timeout | The timeout (in ms). |
Overrides
Send(DataBuffer)
Sends data synchronously.
Declaration
public override bool Send(DataBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
DataBuffer | buffer | The buffer. |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
SendAsync(DataBuffer, Int32, Action0, Action2<Exception, Boolean>)
Sends data asynchronously.
Declaration
public override void SendAsync(DataBuffer buffer, int timeout, Action0 onSuccess, Action2<Exception, bool> onFailure)
Parameters
Type | Name | Description |
---|---|---|
DataBuffer | buffer | The buffer. |
System.Int32 | timeout | The timeout (in ms). |
Action0 | onSuccess | The callback to invoke on success. |
Action2<System.Exception, System.Boolean> | onFailure | The callback to invoke on failure. |
Overrides
Events
OnSocketCreated
Raised when a socket has been created and initialized.
Declaration
public static event Action1<TcpSocket> OnSocketCreated
Event Type
Type | Description |
---|---|
Action1<TcpSocket> |