DarkWS.Client.DarkWsClient
DarkWS.Client
DarkWS.Client
DarkWsClient Class
A concurrent, lazy DarkWS client. One instance owns one server session.
public sealed class DarkWsClient : DarkWS.Client.IDarkWsClient, System.IDisposable, System.IAsyncDisposable
Inheritance System.Object → DarkWsClient
Implements IDarkWsClient, System.IDisposable, System.IAsyncDisposable
Constructors
DarkWsClient(DarkWsClientOptions) Constructor
Validates and snapshots settings. No connection is opened.
public DarkWsClient(DarkWS.Client.DarkWsClientOptions options);
Parameters
options DarkWsClientOptions
DarkWsClient(Uri) Constructor
Creates a client using default settings. No connection is opened.
public DarkWsClient(System.Uri endpoint);
Parameters
endpoint System.Uri
Properties
DarkWsClient.State Property
Current connection readiness.
public DarkWS.Client.DarkWsClientState State { get; }
Implements State
Property Value
Methods
DarkWsClient.AuthenticateAsync(string, CancellationToken) Method
Waits for acknowledged authentication. The supplied token is not retained for reconnect.
public System.Threading.Tasks.Task AuthenticateAsync(string token, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
token System.String
cancellationToken System.Threading.CancellationToken
Implements AuthenticateAsync(string, CancellationToken)
Returns
DarkWsClient.CloseAsync(CancellationToken) Method
Stops reconnect and closes the socket. Explicit ConnectAsync allows reuse.
public System.Threading.Tasks.Task CloseAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
cancellationToken System.Threading.CancellationToken
Implements CloseAsync(CancellationToken)
Returns
DarkWsClient.ConnectAsync(CancellationToken) Method
Starts or joins a connection cycle. Cancelling the wait does not stop other callers.
public System.Threading.Tasks.Task ConnectAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
cancellationToken System.Threading.CancellationToken
Implements ConnectAsync(CancellationToken)
Returns
DarkWsClient.Dispose() Method
Immediately stops network activity. Prefer DisposeAsync when awaiting network cleanup is possible.
public void Dispose();
Implements Dispose()
DarkWsClient.DisposeAsync() Method
Closes an open connection gracefully within CloseTimeout, then stops and awaits internal network tasks. Does not wait indefinitely for application callbacks.
public System.Threading.Tasks.ValueTask DisposeAsync();
Implements DisposeAsync()
Returns
System.Threading.Tasks.ValueTask
DarkWsClient.LogoutAsync(CancellationToken) Method
Disables automatic session authentication and waits for acknowledged logout.
public System.Threading.Tasks.Task LogoutAsync(System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
cancellationToken System.Threading.CancellationToken
Implements LogoutAsync(CancellationToken)
Returns
DarkWsClient.On(string, Action) Method
Subscribes to an action, ignoring its optional payload. Dispose to unsubscribe.
public System.IDisposable On(string action, System.Action handler);
Parameters
action System.String
handler System.Action
Implements On(string, Action)
Returns
DarkWsClient.On<T>(string, Action<T>) Method
Subscribes to typed action data. Callbacks run off the UI context, in delivery order.
public System.IDisposable On<T>(string action, System.Action<T> handler);
Type parameters
T
Parameters
action System.String
handler System.Action<T>
Implements On<T>(string, Action<T>)
Returns
DarkWsClient.OnAsync<T>(string, Func<T,CancellationToken,Task>) Method
Subscribes to async typed callbacks. Cancellation signals loss of the originating connection.
public System.IDisposable OnAsync<T>(string action, System.Func<T,System.Threading.CancellationToken,System.Threading.Tasks.Task> handler);
Type parameters
T
Parameters
action System.String
handler System.Func<T,System.Threading.CancellationToken,System.Threading.Tasks.Task>
Implements OnAsync<T>(string, Func<T,CancellationToken,Task>)
Returns
DarkWsClient.RequestAsync(string, object, CancellationToken) Method
Sends a payload and waits for success, ignoring returned data.
public System.Threading.Tasks.Task RequestAsync(string action, object? payload, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
action System.String
payload System.Object
cancellationToken System.Threading.CancellationToken
Implements RequestAsync(string, object, CancellationToken)
Returns
DarkWsClient.RequestAsync(string, CancellationToken) Method
Sends a request without a payload and waits for success, ignoring returned data.
public System.Threading.Tasks.Task RequestAsync(string action, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Parameters
action System.String
cancellationToken System.Threading.CancellationToken
Implements RequestAsync(string, CancellationToken)
Returns
DarkWsClient.RequestAsync<TResponse>(string, object, CancellationToken) Method
Sends a payload, including explicit null, and deserializes the required data field.
public System.Threading.Tasks.Task<TResponse> RequestAsync<TResponse>(string action, object? payload, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Type parameters
TResponse
Parameters
action System.String
payload System.Object
cancellationToken System.Threading.CancellationToken
Implements RequestAsync<TResponse>(string, object, CancellationToken)
Returns
System.Threading.Tasks.Task<TResponse>
DarkWsClient.RequestAsync<TResponse>(string, CancellationToken) Method
Sends a request without a payload and deserializes its required data field.
public System.Threading.Tasks.Task<TResponse> RequestAsync<TResponse>(string action, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));
Type parameters
TResponse
Parameters
action System.String
cancellationToken System.Threading.CancellationToken
Implements RequestAsync<TResponse>(string, CancellationToken)
Returns
System.Threading.Tasks.Task<TResponse>
Events
DarkWsClient.Error Event
Background and subscriber errors. Request errors are returned through their tasks.
public event EventHandler<DarkWsClientErrorEventArgs>? Error;
Implements Error
Event Type
System.EventHandler<DarkWsClientErrorEventArgs>
DarkWsClient.StateChanged Event
Ordered state transitions delivered outside the socket reader and internal locks.
public event EventHandler<DarkWsStateChangedEventArgs>? StateChanged;
Implements StateChanged