Class WebSocketMessageHandler
- Namespace
- StreamJsonRpc
- Assembly
- StreamJsonRpc.dll
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
WebSocketThe 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
WebSocketThe WebSocket used to communicate. This will not be automatically disposed of with this WebSocketMessageHandler.
formatter
IJsonRpcMessageFormatterThe formatter to use to serialize JsonRpcMessage instances.
sizeHint
intThe 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
CanWrite
Gets a value indicating whether this message handler can send messages.
public override bool CanWrite { get; }
Property Value
WebSocket
Gets the WebSocket used to communicate.
public WebSocket WebSocket { get; }
Property Value
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
CancellationTokenA 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
CancellationTokenA 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
JsonRpcMessageThe message to write.
cancellationToken
CancellationTokenA token to cancel the transmission.
Returns
- ValueTask
A task that represents the asynchronous write operation.