Table of Contents

Class ClientWebSocket

Namespace
System.Net.WebSockets
Assembly
System.Net.WebSockets.dll

Provides a client for connecting to WebSocket services.

public class ClientWebSocket : WebSocket, IDisposable
Inheritance
ClientWebSocket
Implements
Inherited Members
Extension Methods

Constructors

ClientWebSocket(ClientWebSocketOptions)

Creates an instance of the WebSocketClient class.

public ClientWebSocket(ClientWebSocketOptions options = null)

Parameters

options ClientWebSocketOptions

Optional ClientWebSocketOptions where extra options can be defined.

Properties

CACertificate

Gets or sets the root CA certificate used to authenticate with secure servers. This certificate is used only for wss connections; ws connections do not require this.

public X509Certificate CACertificate { get; set; }

Property Value

X509Certificate

Host

The remote Host name to connect to.

public string Host { get; }

Property Value

string

IsSSL

If a secure connection is used.

public bool IsSSL { get; }

Property Value

bool

Port

The remote Port to connect to.

public int Port { get; }

Property Value

int

Prefix

The remote Prefix to connect to.

public string Prefix { get; }

Property Value

string

SslProtocol

Gets or sets the TLS/SSL protocol used by the WebSocket class.

public SslProtocols SslProtocol { get; }

Property Value

SslProtocols

One of the values defined in the SslProtocols enumeration.

SslVerification

Option for SSL verification. The default behavior is CertificateRequired.

public SslVerification SslVerification { get; set; }

Property Value

SslVerification

State

Gets the WebSocket state of the ClientWebSocket instance.

public override WebSocketState State { get; set; }

Property Value

WebSocketState

The WebSocket state of the ClientWebSocket instance.

UseCustomCertificate

Option to use a custom certificate for authentication.

public bool UseCustomCertificate { get; }

Property Value

bool

UseStoredDeviceCertificate

Option to use the certificate stored in the device as client or server certificate. The default option is false.

public bool UseStoredDeviceCertificate { get; set; }

Property Value

bool

Methods

Connect(string, ClientWebSocketHeaders)

Connect to a WebSocket server.

public void Connect(string uri, ClientWebSocketHeaders headers = null)

Parameters

uri string

The URI of the WebSocket server to connect to.

headers ClientWebSocketHeaders

Optional ClientWebSocketHeaders for setting custom headers.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()