Casper.Network.SDK
Show / Hide Table of Contents

Class ServerEventsClient

The client used to subscribe to events emitted by a Casper node.

Inheritance
object
ServerEventsClient
Implements
ISSEClient
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Casper.Network.SDK.SSE
Assembly: Casper.Network.SDK.dll
Syntax
public class ServerEventsClient : ISSEClient
Remarks

Instantiate the ServerEventsClient class indicating the host and the port of the node that you want to connect to. Then, add one or more event callback methods to subscribe to some of the EventTypes offered by the node and start to listen to the event stream.
Refer to the AwaitEvents for a practical example that shows how to use this class.

Constructors

| Edit this page View Source

ServerEventsClient()

Declaration
public ServerEventsClient()
| Edit this page View Source

ServerEventsClient(string)

Instantiate the class indicating the full SSE stream URL of a node. Example: https://node.testnet.casper.network/events

Declaration
public ServerEventsClient(string sseUrl)
Parameters
Type Name Description
string sseUrl

Full URL of the SSE stream.

Remarks

Use this constructor when the node is running version 2.x of the Casper protocol.

| Edit this page View Source

ServerEventsClient(string, int, int)

Instantiate the class indicating the host and the port of a node.

Declaration
public ServerEventsClient(string host, int port, int nodeVersion = 2)
Parameters
Type Name Description
string host

IP or domain name of the node.

int port

Event stream port.

int nodeVersion

2 for Casper 2.x; 1 for Casper 1.x.

Fields

| Edit this page View Source

_host

Declaration
protected string _host
Field Value
Type Description
string
| Edit this page View Source

_nodeVersion

Declaration
protected int _nodeVersion
Field Value
Type Description
int
| Edit this page View Source

_port

Declaration
protected int _port
Field Value
Type Description
int
| Edit this page View Source

_sseUri

Declaration
protected Uri _sseUri
Field Value
Type Description
Uri

Properties

| Edit this page View Source

NodeVersion

Declaration
public int NodeVersion { get; set; }
Property Value
Type Description
int

Methods

| Edit this page View Source

AddEventCallback(EventType, string, EventCallback, int)

Adds an event callback method that is called for each subscribed event emitted by the node.

Declaration
public void AddEventCallback(EventType eventType, string name, EventCallback cb, int startFrom = 2147483647)
Parameters
Type Name Description
EventType eventType

One or more event types to subscribe to.

string name

Name of the callback. Use it later to remove the callback when needed.

EventCallback cb

Callback method to call.

int startFrom

The minimum Id number in the event stream that we want to receive.

| Edit this page View Source

IsRunning()

Declaration
public bool IsRunning()
Returns
Type Description
bool
| Edit this page View Source

RemoveEventCallback(EventType, string)

Removes an event callback method from the client.

Declaration
public bool RemoveEventCallback(EventType eventType, string name)
Parameters
Type Name Description
EventType eventType

Event types subscribed in the callback method.

string name

Name of the callback.

Returns
Type Description
bool
| Edit this page View Source

StartListening()

Connects to the node and starts listening to its even stream. If no callback method has been added, this method throws an exception.

Declaration
public void StartListening()
Exceptions
Type Condition
Exception
| Edit this page View Source

StopListening()

Stops listening to the event stream and disconnects from the node.

Declaration
public Task StopListening()
Returns
Type Description
Task
| Edit this page View Source

Wait()

Blocks the calling thread until all channels are disconnected.

Declaration
public void Wait()
| Edit this page View Source

_getHttpClient()

Returns an instance of an HttpClient. Derived classes can override this method to get the client object from an HttpClientFactory, for example.

Declaration
protected virtual HttpClient _getHttpClient()
Returns
Type Description
HttpClient

a new or recycled instance of HttpClient

Implements

ISSEClient
  • Edit this page
  • View Source
In this article
Back to top Maintained by MAKE Technology LLC