Table of Contents

Interface IRustPlusSocket

Namespace
RustPlusApi.Interfaces
Assembly
RustPlusApi.dll

Low-level WebSocket contract โ€” connection lifecycle and raw message events. Clients are disposable; prefer DisposeAsync() so teardown drains background work.

public interface IRustPlusSocket : IDisposable, IAsyncDisposable
Inherited Members

Properties

IsConnected

Gets a value indicating whether the WebSocket connection is currently open.

bool IsConnected { get; }

Property Value

bool

Methods

ConnectAsync(CancellationToken)

Opens the WebSocket connection to the server. On failure, ErrorOccurred is raised and the exception is rethrown. May be called again after a disconnect to reconnect.

Task ConnectAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to cancel the connection attempt.

Returns

Task

Exceptions

ObjectDisposedException

Thrown when the client has been disposed.

InvalidOperationException

Thrown when the client is already connected.

DisconnectAsync(bool)

Closes the WebSocket connection.

Task DisconnectAsync(bool forceClose = false)

Parameters

forceClose bool

When true, aborts the connection immediately instead of sending a close handshake.

Returns

Task

Events

Connected

Raised when the WebSocket connection is established.

event EventHandler? Connected

Event Type

EventHandler

Connecting

Raised just before the WebSocket connection attempt begins.

event EventHandler? Connecting

Event Type

EventHandler

Disconnected

Raised after the WebSocket connection has been closed.

event EventHandler? Disconnected

Event Type

EventHandler

Disconnecting

Raised just before the WebSocket connection is closed.

event EventHandler? Disconnecting

Event Type

EventHandler

ErrorOccurred

Raised when an unhandled exception occurs on the receive loop.

event EventHandler<Exception>? ErrorOccurred

Event Type

EventHandler<Exception>

MessageReceived

Raised for every inbound AppMessage, before routing.

event EventHandler<AppMessage>? MessageReceived

Event Type

EventHandler<AppMessage>

NotificationReceived

Raised for inbound messages that are push notifications (no matching pending request).

event EventHandler<AppMessage>? NotificationReceived

Event Type

EventHandler<AppMessage>

RequestSent

Raised after a request has been serialized and sent.

event EventHandler<AppRequest>? RequestSent

Event Type

EventHandler<AppRequest>

ResponseReceived

Raised for inbound messages that are responses to a pending request.

event EventHandler<AppMessage>? ResponseReceived

Event Type

EventHandler<AppMessage>

SendingRequest

Raised when a request is about to be sent to the server.

event EventHandler? SendingRequest

Event Type

EventHandler