Search Results for

    Show / Hide Table of Contents

    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
    object
    WebSocketClient<TInput, TOutput>
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Glitch9.IO.Networking.WebSocket
    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
    Type Name Description
    string clientName
    IWebSocketListener<TOutput> listener
    IWebSocketStateListener stateListener
    JsonSerializerSettings jss
    int byteSize
    ILogger logger

    Properties

    | Edit this page View Source

    Name

    Declaration
    public string Name { get; }
    Property Value
    Type Description
    string
    | Edit this page View Source

    State

    Declaration
    public WebSocketState State { get; }
    Property Value
    Type Description
    WebSocketState
    | Edit this page View Source

    WebSocket

    Declaration
    public IWebSocket WebSocket { get; }
    Property Value
    Type Description
    IWebSocket

    Methods

    | Edit this page View Source

    AddListener(IWebSocketListener<TOutput>)

    Declaration
    public void AddListener(IWebSocketListener<TOutput> listener)
    Parameters
    Type Name Description
    IWebSocketListener<TOutput> listener
    | Edit this page View Source

    AddStateListener(IWebSocketStateListener)

    Declaration
    public void AddStateListener(IWebSocketStateListener stateListener)
    Parameters
    Type Name Description
    IWebSocketStateListener stateListener
    | 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
    Type Name Description
    WebSocketCloseStatus closeStatus
    string closeDescription
    CancellationToken cancellationToken
    Returns
    Type Description
    UniTask
    | Edit this page View Source

    CreateConnectionAsync(string, params HttpHeader[])

    Declaration
    public UniTask<IWebSocket> CreateConnectionAsync(string url, params HttpHeader[] headers)
    Parameters
    Type Name Description
    string url
    HttpHeader[] headers
    Returns
    Type Description
    UniTask<IWebSocket>
    | Edit this page View Source

    CreateConnectionAsync(string, CancellationToken, params HttpHeader[])

    Declaration
    public UniTask<IWebSocket> CreateConnectionAsync(string url, CancellationToken cancellationToken, params HttpHeader[] headers)
    Parameters
    Type Name Description
    string url
    CancellationToken cancellationToken
    HttpHeader[] headers
    Returns
    Type Description
    UniTask<IWebSocket>
    | Edit this page View Source

    Dispose()

    Declaration
    public void Dispose()
    | 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

    ReconnectAsync(string, IEnumerable<HttpHeader>, CancellationToken)

    Declaration
    public UniTask<IWebSocket> ReconnectAsync(string url = null, IEnumerable<HttpHeader> headers = null, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string url
    IEnumerable<HttpHeader> headers
    CancellationToken cancellationToken
    Returns
    Type Description
    UniTask<IWebSocket>
    | Edit this page View Source

    RemoveListener(IWebSocketListener<TOutput>)

    Declaration
    public void RemoveListener(IWebSocketListener<TOutput> listener)
    Parameters
    Type Name Description
    IWebSocketListener<TOutput> listener
    | Edit this page View Source

    RemoveStateListener(IWebSocketStateListener)

    Declaration
    public void RemoveStateListener(IWebSocketStateListener stateListener)
    Parameters
    Type Name Description
    IWebSocketStateListener stateListener
    | Edit this page View Source

    SendAsync(byte[], CancellationToken)

    Declaration
    public UniTask SendAsync(byte[] data, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    byte[] data
    CancellationToken cancellationToken
    Returns
    Type Description
    UniTask
    | Edit this page View Source

    SendAsync(object, CancellationToken)

    Declaration
    public UniTask SendAsync(object message, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    object message
    CancellationToken cancellationToken
    Returns
    Type Description
    UniTask
    | Edit this page View Source

    SendAsync(string, CancellationToken)

    Declaration
    public UniTask SendAsync(string message, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    string message
    CancellationToken cancellationToken
    Returns
    Type Description
    UniTask
    | Edit this page View Source

    SendAsync(TInput, CancellationToken)

    Declaration
    public UniTask SendAsync(TInput input, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    TInput input
    CancellationToken cancellationToken
    Returns
    Type Description
    UniTask
    | Edit this page View Source

    StartListening(CancellationToken)

    Declaration
    public void StartListening(CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    Extension Methods

    ArrayExtensions.ToArrayOrEmpty<T>(T)
    ArrayExtensions.ToArrayOrNull<T>(T)
    EventExtensions.ToDelta<T>(T, string, int, string, bool)
    EventExtensions.ToDone<T>(T, string, int, string)
    EventExtensions.ToEvent<T>(T)
    EventExtensions.UpcastDelta<T1, T2>(T1, string, int, string, bool)
    FallbackExtensions.IsOr<TParent, TChild>(TParent, TChild)
    ResponseCastingExtensions.GetResult<T>(T)
    SystemExtensions.GetName(object)
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation