InvergeDocs
.NETAPI reference

Realtime socket

Realtime socket in the .NET SDK.

SymbolKindSummary
NexusRealtimeErrorEventArgsclassWhy a realtime connection failed or dropped.
NexusRealtimeMessageclassOne message received from a realtime room.
NexusRealtimeOptionsclassHow the realtime connection behaves.
NexusRealtimeSocketclassA Socket.IO connection to the Nexus realtime plane, for receiving room traffic.

NexusRealtimeErrorEventArgs

class Inverge.Nexus.Realtime
class Inverge.Nexus.Realtime.NexusRealtimeErrorEventArgs

Why a realtime connection failed or dropped.

Exception

property
Exception? Exception { get; }

The underlying exception, when there was one.

IsBillingSuspended

property
bool IsBillingSuspended { get; }

Whether the handshake was refused because the organisation's data plane is suspended for unpaid invoices.

The server reports this distinctly from a bad key precisely so a client can tell "pay the bill" apart from "fix your credentials" and stop retrying.

IsUnauthorized

property
bool IsUnauthorized { get; }

Whether the API key was rejected.

Message

property
string Message { get; }

The server's message, or the transport's.

NexusRealtimeMessage

class Inverge.Nexus.Realtime
class Inverge.Nexus.Realtime.NexusRealtimeMessage

One message received from a realtime room.

EventName

property
string EventName { get; }

The event name the message was emitted under.

Payload

property
JsonNode? Payload { get; }

The payload, as JSON. null when the emit carried none.

RawText

property
string? RawText { get; }

The raw frame text, for when the payload will not parse as expected.

As()

method
T? As<T>(JsonSerializerOptions? options = null)

Deserializes the payload into T.

Reflection-based, so a trimmed or native-AOT host should read Payload directly, or pass a options built from a source-generated context.

Parameters

Prop

Type

Returns T?

NexusRealtimeOptions

class Inverge.Nexus.Realtime
class Inverge.Nexus.Realtime.NexusRealtimeOptions

How the realtime connection behaves.

NexusRealtimeOptions

constructor
new NexusRealtimeOptions()

AckTimeout

property
TimeSpan AckTimeout { get; set; }

How long to wait for a server acknowledgement of join, leave or emit.

ConnectionTimeout

property
TimeSpan ConnectionTimeout { get; set; }

How long to wait for the handshake.

DeviceKey

property
string? DeviceKey { get; set; }

The device key to correlate this connection with.

DistinctId

property
string? DistinctId { get; set; }

The identity to connect as, carried in the handshake.

Optional, and only used for the user-journey correlation of realtime traffic. Room membership does not depend on it.

ExtraHeaders

property
IDictionary<string, string> ExtraHeaders { get; }

Extra handshake headers.

PreferWebSocket

property
bool PreferWebSocket { get; set; }

Connect over WebSocket immediately rather than upgrading from long-polling.

On by default: a server-side listener has no reason to start on polling, and skipping the upgrade removes a round trip and a class of proxy-breaks-the-upgrade failure.

Reconnection

property
bool Reconnection { get; set; }

Reconnect automatically after a dropped connection.

ReconnectionAttempts

property
int ReconnectionAttempts { get; set; }

How many reconnect attempts before giving up.

ReconnectionDelayMax

property
TimeSpan ReconnectionDelayMax { get; set; }

Longest delay between reconnect attempts.

SessionKey

property
string? SessionKey { get; set; }

The session key to correlate this connection with.

StopOnBillingSuspended

property
bool StopOnBillingSuspended { get; set; }

Stop reconnecting when the server refuses the handshake with billing_suspended.

On by default, and worth leaving on. A suspension is resolved by paying an invoice, not by retrying: a client that keeps reconnecting hammers the server every few seconds for as long as the suspension lasts, and buries the one error message that would have explained it.

Url

property
string? Url { get; set; }

The Socket.IO origin. Defaults to the client's RealtimeUrl, or its API origin.

NexusRealtimeSocket

class Inverge.Nexus.Realtime
class Inverge.Nexus.Realtime.NexusRealtimeSocket

A Socket.IO connection to the Nexus realtime plane, for receiving room traffic.

The core SDK's Realtime resource only emits. Use this when a .NET process needs to listen — a worker reacting to room traffic, a bridge into another system, a test harness.

Rooms are environment-scoped. The key you connect with must belong to the same environment that emits, or you will sit in silence that looks exactly like a bug in your handler.

Handlers registered before connecting are attached on connect, and joined rooms are re-joined after every reconnect — server-side membership does not survive one, so without that a reconnected socket goes quiet permanently.

NexusRealtimeSocket

constructor
new NexusRealtimeSocket(INexusClient client, Action<NexusRealtimeOptions>? configure = null)

Creates a socket from a configured client.

Parameters

Prop

Type

NexusRealtimeSocket

constructor
new NexusRealtimeSocket(NexusOptions options, Action<NexusRealtimeOptions>? configure = null)

Creates a socket from options.

Parameters

Prop

Type

IsConnected

property
bool IsConnected { get; }

Whether the socket is currently connected.

Rooms

property
IReadOnlyCollection<string> Rooms { get; }

The rooms this socket believes it has joined.

SocketId

property
string? SocketId { get; }

The server's id for this socket, once connected.

Connected

event
event EventHandler Connected

Raised once the handshake succeeds, including after a reconnect.

Disconnected

event
event EventHandler<string> Disconnected

Raised when the connection drops, carrying the reason.

Error

event
event EventHandler<NexusRealtimeErrorEventArgs> Error

Raised when the server refuses the connection or reports an error.

ConnectAsync()

method
Task ConnectAsync(CancellationToken cancellationToken = default)

Opens the connection. Idempotent.

Parameters

Prop

Type

DisconnectAsync()

method
Task DisconnectAsync()

Closes the connection.

DisposeAsync()

method
ValueTask DisposeAsync()

Returns ValueTask

EmitAsync()

method
Task<JsonNode?> EmitAsync(string room, string eventName, object? payload = null, CancellationToken cancellationToken = default)

Emits over the socket.

From a server, the HTTP client.Realtime.EmitAsync is usually the better choice: it needs no live connection and it is retried and reported like any other API call.

Parameters

Prop

Type

Returns Task<JsonNode?>

JoinAsync()

method
Task<JsonNode?> JoinAsync(string room, CancellationToken cancellationToken = default)

Joins a room. Idempotent, and re-applied automatically after a reconnect.

Parameters

Prop

Type

Returns Task<JsonNode?>

LeaveAsync()

method
Task<JsonNode?> LeaveAsync(string room, CancellationToken cancellationToken = default)

Leaves a room, and stops re-joining it on reconnect.

Parameters

Prop

Type

Returns Task<JsonNode?>

Off()

method
void Off(string eventName)

Removes every handler for an event name.

Parameters

Prop

Type

On()

method
void On(string eventName, Func<NexusRealtimeMessage, Task> handler)

Registers an async handler for an event name. Several handlers per event are allowed.

Parameters

Prop

Type

On()

method
void On(string eventName, Action<NexusRealtimeMessage> handler)

Registers a synchronous handler for an event name.

Parameters

Prop

Type

On this page