Class WebSocketClient<TInput, TOutput>
2025-09-24: Added binary receive support and improved message assembly.
2025-10-15: Extended to separate input and output message types.
2025-11-16: Refactored cancellation design to use CancellationToken.
Inheritance
WebSocketClient<TInput, TOutput>
Assembly: Glitch9.IO.dll
Syntax
public class WebSocketClient<TInput, TOutput> where TInput : IWebSocketMessage where TOutput : IWebSocketMessage
Type Parameters
| Name |
Description |
| TInput |
The type of WebSocket message to send, which must implement IWebSocketMessage.
|
| TOutput |
The type of WebSocket message to receive, which must implement IWebSocketMessage.
|
Constructors
|
Edit this page
View Source
WebSocketClient(string, IWebSocketListener<TOutput>, IWebSocketStateListener, JsonSerializerSettings, int, ILogger)
Declaration
public WebSocketClient(string clientName, IWebSocketListener<TOutput> listener = null, IWebSocketStateListener stateListener = null, JsonSerializerSettings jss = null, int byteSize = 1024, ILogger logger = null)
Parameters
Properties
|
Edit this page
View Source
Name
Declaration
public string Name { get; }
Property Value
|
Edit this page
View Source
State
Declaration
public WebSocketState State { get; }
Property Value
|
Edit this page
View Source
WebSocket
Declaration
public IWebSocket WebSocket { get; }
Property Value
Methods
|
Edit this page
View Source
AddListener(IWebSocketListener<TOutput>)
Declaration
public void AddListener(IWebSocketListener<TOutput> listener)
Parameters
|
Edit this page
View Source
AddStateListener(IWebSocketStateListener)
Declaration
public void AddStateListener(IWebSocketStateListener stateListener)
Parameters
|
Edit this page
View Source
CancelAllOperations()
Cancels all operations started by this client (global shutdown).
Declaration
public void CancelAllOperations()
|
Edit this page
View Source
CloseConnectionAsync(WebSocketCloseStatus, string, CancellationToken)
Declaration
public UniTask CloseConnectionAsync(WebSocketCloseStatus closeStatus = WebSocketCloseStatus.NormalClosure, string closeDescription = "No reason provided.", CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public UniTask<IWebSocket> CreateConnectionAsync(string url, params HttpHeader[] headers)
Parameters
Returns
|
Edit this page
View Source
Declaration
public UniTask<IWebSocket> CreateConnectionAsync(string url, CancellationToken cancellationToken, params HttpHeader[] headers)
Parameters
Returns
|
Edit this page
View Source
Dispose()
Declaration
|
Edit this page
View Source
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type |
Name |
Description |
| bool |
disposing |
|
|
Edit this page
View Source
~WebSocketClient()
Declaration
protected ~WebSocketClient()
|
Edit this page
View Source
Declaration
public UniTask<IWebSocket> ReconnectAsync(string url = null, IEnumerable<HttpHeader> headers = null, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
RemoveListener(IWebSocketListener<TOutput>)
Declaration
public void RemoveListener(IWebSocketListener<TOutput> listener)
Parameters
|
Edit this page
View Source
RemoveStateListener(IWebSocketStateListener)
Declaration
public void RemoveStateListener(IWebSocketStateListener stateListener)
Parameters
|
Edit this page
View Source
SendAsync(byte[], CancellationToken)
Declaration
public UniTask SendAsync(byte[] data, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
SendAsync(object, CancellationToken)
Declaration
public UniTask SendAsync(object message, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
SendAsync(string, CancellationToken)
Declaration
public UniTask SendAsync(string message, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
SendAsync(TInput, CancellationToken)
Declaration
public UniTask SendAsync(TInput input, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
StartListening(CancellationToken)
Declaration
public void StartListening(CancellationToken cancellationToken = default)
Parameters
Extension Methods