Table of Contents

Class WebSocketMessageHandler

Namespace
StreamJsonRpc
Assembly
StreamJsonRpc.dll

A message handler for the JsonRpc class that uses WebSocket as the transport.

public class WebSocketMessageHandler : MessageHandlerBase, IJsonRpcMessageHandler, IDisposableObservable, IDisposable, IAsyncDisposable, IJsonRpcMessageBufferManager
Inheritance
WebSocketMessageHandler
Implements
Inherited Members

Constructors

WebSocketMessageHandler(WebSocket)

Initializes a new instance of the WebSocketMessageHandler class that uses the JsonMessageFormatter to serialize messages as textual JSON.

public WebSocketMessageHandler(WebSocket webSocket)

Parameters

webSocket WebSocket

The WebSocket used to communicate. This will not be automatically disposed of with this WebSocketMessageHandler.

WebSocketMessageHandler(WebSocket, IJsonRpcMessageFormatter, int)

Initializes a new instance of the WebSocketMessageHandler class.

public WebSocketMessageHandler(WebSocket webSocket, IJsonRpcMessageFormatter formatter, int sizeHint = 4096)

Parameters

webSocket WebSocket

The WebSocket used to communicate. This will not be automatically disposed of with this WebSocketMessageHandler.

formatter IJsonRpcMessageFormatter

The formatter to use to serialize JsonRpcMessage instances.

sizeHint int

The size of the buffer to use for reading JSON-RPC messages. Messages which exceed this size will be handled properly but may require multiple I/O operations.

Properties

CanRead

Gets a value indicating whether this message handler can receive messages.

public override bool CanRead { get; }

Property Value

bool

CanWrite

Gets a value indicating whether this message handler can send messages.

public override bool CanWrite { get; }

Property Value

bool

WebSocket

Gets the WebSocket used to communicate.

public WebSocket WebSocket { get; }

Property Value

WebSocket

Methods

FlushAsync(CancellationToken)

Ensures that all messages transmitted up to this point are en route to their destination, rather than sitting in some local buffer.

protected override ValueTask FlushAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

ValueTask

A Task that completes when the write buffer has been transmitted, or at least that the operation is in progress, if final transmission cannot be tracked.

ReadCoreAsync(CancellationToken)

Reads a distinct and complete message, waiting for one if necessary.

protected override ValueTask<JsonRpcMessage?> ReadCoreAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to cancel the read request.

Returns

ValueTask<JsonRpcMessage>

A task whose result is the received message. A null string indicates the stream has ended. An empty string should never be returned.

WriteCoreAsync(JsonRpcMessage, CancellationToken)

Writes a message.

protected override ValueTask WriteCoreAsync(JsonRpcMessage content, CancellationToken cancellationToken)

Parameters

content JsonRpcMessage

The message to write.

cancellationToken CancellationToken

A token to cancel the transmission.

Returns

ValueTask

A task that represents the asynchronous write operation.