Table of Contents

Class WebSocketRpcClient

Namespace
chia.dotnet
Assembly
chia-dotnet.dll

Class that handles core communication with the rpc endpoint using a WebSocket (wss). Only the daemon endpoint supports WebSockets, but it can proxy communication to other services. Destination

public class WebSocketRpcClient : IRpcClient, IDisposable
Inheritance
WebSocketRpcClient
Implements
Inherited Members
Extension Methods

Constructors

WebSocketRpcClient(EndpointInfo)

ctor

public WebSocketRpcClient(EndpointInfo endpoint)

Parameters

endpoint EndpointInfo

Details of the WebSocket endpoint

Properties

Endpoint

Details of the RPC service endpoint

public EndpointInfo Endpoint { get; init; }

Property Value

EndpointInfo
Class that handles core communication with the rpc endpoint using a WebSocket (wss). Only the daemon endpoint supports WebSockets, but it can proxy communication to other services.

Methods

Close(CancellationToken)

Cancels the receive loop and closes the WebSocket

public Task Close(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to allow the call to be cancelled

Returns

Task

Awaitable Task

Connect(CancellationToken)

Opens the WebSocket and starts the receive loop

public Task Connect(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to allow the call to be cancelled

Returns

Task

An awaitable Task

Dispose()

public void Dispose()

Dispose(bool)

Called when the instance is being disposed or finalized

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Invoke from Dispose()

OnBroadcastMessageReceived(Message)

Raises the BroadcastMessageReceived event

protected virtual void OnBroadcastMessageReceived(Message message)

Parameters

message Message

The message to broadcast

OnConnected()

Called after Connect(CancellationToken) completes successfully. Lets derived classes know that they can do post connection initialization

protected virtual void OnConnected()

PostMessage(Message, CancellationToken)

Posts a Message to the WebSocket but does not wait for a response

public virtual Task PostMessage(Message message, CancellationToken cancellationToken = default)

Parameters

message Message

The message to post

cancellationToken CancellationToken

A token to allow the call to be cancelled

Returns

Task

Awaitable Task

Remarks

Awaiting this method waits for the message to be sent only. It doesn't await a response.

SendMessage(Message, CancellationToken)

Sends a Message to the endpoint and waits for a response

public Task<dynamic> SendMessage(Message message, CancellationToken cancellationToken = default)

Parameters

message Message

The message to send

cancellationToken CancellationToken

A token to allow the call to be cancelled

Returns

Task<dynamic>

The response message

Remarks

Awaiting this method will block until a response is received from the WebSocket or the A token to allow the call to be cancelled is cancelled

Exceptions

ResponseException

Throws when IsSuccessfulResponse is False

Events

BroadcastMessageReceived

Event raised when a message is received from the endpoint that was either not in response to a request or was a response from a posted message (i.e. we didn't register to receive the response) Pooling state_changed messages come through this event

public event EventHandler<Message>? BroadcastMessageReceived

Event Type

EventHandler<Message>
Class that handles core communication with the rpc endpoint using a WebSocket (wss). Only the daemon endpoint supports WebSockets, but it can proxy communication to other services.

Remarks

You need to call RegisterService(string, CancellationToken) with wallet_ui in order for service events to be generated.