Class WebSocketClient
The default, native-based WebSocket client implementation.
Inheritance
Implements
Namespace: DisCatSharp.Net.WebSocket
Assembly: DisCatSharp.dll
Syntax
public class WebSocketClient : IWebSocketClient, IDisposable
Properties
| Improve this Doc View SourceDefaultHeaders
Gets the collection of default headers to send when connecting to the remote endpoint.
Declaration
public IReadOnlyDictionary<string, string> DefaultHeaders { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyDictionary<System.String, System.String> |
Proxy
Gets the proxy settings for this client.
Declaration
public IWebProxy Proxy { get; }
Property Value
Type | Description |
---|---|
System.Net.IWebProxy |
Methods
| Improve this Doc View SourceAddDefaultHeader(String, String)
Adds a header to the default header collection.
Declaration
public bool AddDefaultHeader(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the header to add. |
System.String | value | Value of the header to add. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the operation succeeded. |
ConnectAsync(Uri)
Connects to a specified remote WebSocket endpoint.
Declaration
public async Task ConnectAsync(Uri uri)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | uri | The URI of the WebSocket endpoint. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
CreateNew(IWebProxy, IServiceProvider)
Creates a new instance of WebSocketClient.
Declaration
public static IWebSocketClient CreateNew(IWebProxy proxy, IServiceProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.Net.IWebProxy | proxy | Proxy to use for this client instance. |
System.IServiceProvider | provider | Service provider. |
Returns
Type | Description |
---|---|
IWebSocketClient | An instance of WebSocketClient. |
DisconnectAsync(Int32, String)
Disconnects the WebSocket connection.
Declaration
public async Task DisconnectAsync(int code = 1000, string message = "")
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | code | The code |
System.String | message | The message |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Dispose()
Disposes of resources used by this WebSocket client instance.
Declaration
public void Dispose()
RemoveDefaultHeader(String)
Removes a header from the default header collection.
Declaration
public bool RemoveDefaultHeader(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the header to remove. |
Returns
Type | Description |
---|---|
System.Boolean | Whether the operation succeeded. |
SendMessageAsync(String)
Send a message to the WebSocket server.
Declaration
public async Task SendMessageAsync(string message)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | The message to send. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Events
| Improve this Doc View SourceConnected
Triggered when the client connects successfully.
Declaration
public event AsyncEventHandler<IWebSocketClient, SocketEventArgs> Connected
Event Type
Type | Description |
---|---|
AsyncEventHandler<IWebSocketClient, SocketEventArgs> |
Disconnected
Triggered when the client is disconnected.
Declaration
public event AsyncEventHandler<IWebSocketClient, SocketCloseEventArgs> Disconnected
Event Type
Type | Description |
---|---|
AsyncEventHandler<IWebSocketClient, SocketCloseEventArgs> |
ExceptionThrown
Triggered when an error occurs in the client.
Declaration
public event AsyncEventHandler<IWebSocketClient, SocketErrorEventArgs> ExceptionThrown
Event Type
Type | Description |
---|---|
AsyncEventHandler<IWebSocketClient, SocketErrorEventArgs> |
MessageReceived
Triggered when the client receives a message from the remote party.
Declaration
public event AsyncEventHandler<IWebSocketClient, SocketMessageEventArgs> MessageReceived
Event Type
Type | Description |
---|---|
AsyncEventHandler<IWebSocketClient, SocketMessageEventArgs> |