Table of Contents

Class HubConnection

Namespace
nanoFramework.SignalR.Client
Assembly
nanoFramework.SignalR.Client.dll

A connection used to invoke hub methods on a SignalR Server. And for server to invoke methods on the client. This client does not support Streams.

public class HubConnection
Inheritance
HubConnection
Inherited Members
Extension Methods

Remarks

A HubConnection should be created using HubConnection. Before hub methods can be invoked the connection must be started using Start(). Clean up a connection using Stop(string).

Constructors

HubConnection(string, ClientWebSocketHeaders, HubConnectionOptions)

Initializes a new instance of the HubConnection class.

public HubConnection(string uri, ClientWebSocketHeaders headers = null, HubConnectionOptions options = null)

Parameters

uri string

Fully Qualified Domain Name of the SignalR Hub server.

headers ClientWebSocketHeaders

Optional ClientWebSocketHeaders for setting custom headers.

options HubConnectionOptions

Optional HubConnectionOptions where extra options can be defined.

Properties

CustomHeaders

Custome headers.

public ClientWebSocketHeaders CustomHeaders { get; }

Property Value

ClientWebSocketHeaders

HandshakeTimeout

Gets or sets the timeout for the initial handshake.

public TimeSpan HandshakeTimeout { get; set; }

Property Value

TimeSpan

KeepAliveInterval

Gets or sets the interval at which the client sends ping messages.

public TimeSpan KeepAliveInterval { get; set; }

Property Value

TimeSpan

Remarks

Sending any message resets the timer to the start of the interval.

ReconnectEnabled

Indicates if reconnection to server is enabled.

public bool ReconnectEnabled { get; }

Property Value

bool

Remarks

Client will only reconnect if this is indicated by the server close message. This can be enabled by setting Reconnect to true. This reconnect function is experimental and perhaps better handled elsewhere.

ServerTimeout

Gets or sets the server timeout interval for the connection.

public TimeSpan ServerTimeout { get; set; }

Property Value

TimeSpan

Remarks

The client times out if it hasn't heard from the server for this long.

State

Indicates the state of the HubConnection to the server.

public HubConnectionState State { get; }

Property Value

HubConnectionState

Uri

The location of the Signalr Hub Server.

public string Uri { get; }

Property Value

string

Remarks

Can be set upon initialization of the HubConnection.

Methods

InvokeCore(string, Type, object[], int)

Invokes a hub method on the server using the specified method name, return type and arguments.

public object InvokeCore(string methodName, Type returnType, object[] args, int timeout = 0)

Parameters

methodName string

The name of the server method to invoke.

returnType Type

The return type of the server method.

args object[]

The arguments used to invoke the server method.

timeout int

The time in milliseconds the server return should be awaited, The default value 0 uses the ServerTimeout

Returns

object

A object response from the server.

Remarks

This is synchronous call that will block your thread, use InvokeCoreAsync(string, Type, object[], int) for a nonblocking asynchronous call.

InvokeCoreAsync(string, Type, object[], int)

Invokes a hub method on the server using the specified method name, return type and arguments.

public AsyncResult InvokeCoreAsync(string methodName, Type returnType, object[] args, int timeout = 0)

Parameters

methodName string

The name of the server method to invoke.

returnType Type

The return type of the server method.

args object[]

The arguments used to invoke the server method.

timeout int

The time in milliseconds the server return should be awaited, The default value 0 uses the ServerTimeout

Returns

AsyncResult

A AsyncResult that represents the asynchronous invoke.

Remarks

This is an asynchronous call

On(string, Type[], OnInvokeHandler)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

public void On(string methodName, Type[] parameterTypes, HubConnection.OnInvokeHandler handler)

Parameters

methodName string

The name of the hub method to define.

parameterTypes Type[]

The parameters types expected by the hub method.

handler HubConnection.OnInvokeHandler

The handler that will be raised when the hub method is invoked.

Remarks

This is a low level method for registering a handler.

SendCore(string, object[])

Invokes a hub method on the server using the specified method name and arguments. Does not wait for a response from the receiver.

public void SendCore(string methodName, object[] args)

Parameters

methodName string

The name of the server method to invoke.

args object[]

The arguments used to invoke the server method.

Remarks

This is a fire and forget implementation

Start()

Starts a connection to the server.

public void Start()

Stop(string)

Stops a connection to the server.

public void Stop(string errorMessage = null)

Parameters

errorMessage string

Optional error message to will be send to the server

Events

Closed

Occurs when the connection is closed. The connection could be closed due to an error or due to either the server or client intentionally closing the connection without error.

public event HubConnection.SignalrEvent Closed

Event Type

HubConnection.SignalrEvent

Remarks

If this event was triggered from a connection error, the System.Exception that occurred will be passed in as the sole argument to this handler. If this event was triggered intentionally by either the client or server, then the argument will be null.

Reconnected

Occurs when the Microsoft.AspNetCore.SignalR.Client.HubConnection successfully reconnects after losing its underlying connection.

public event HubConnection.SignalrEvent Reconnected

Event Type

HubConnection.SignalrEvent

Remarks

The System.String parameter will be the Microsoft.AspNetCore.SignalR.Client.HubConnection's new ConnectionId or null if negotiation was skipped.

Reconnecting

Occurs when the Microsoft.AspNetCore.SignalR.Client.HubConnection starts reconnecting after losing its underlying connection.

public event HubConnection.SignalrEvent Reconnecting

Event Type

HubConnection.SignalrEvent

Remarks

The System.Exception that occurred will be passed in as the sole argument to this handler.