Class ServerEventsClient
The client used to subscribe to events emitted by a Casper node.
Inheritance
Implements
Namespace: Casper.Network.SDK.SSE
Assembly: Casper.Network.SDK.dll
Syntax
public class ServerEventsClient : object, 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
ServerEventsClient()
Declaration
public ServerEventsClient()
ServerEventsClient(String, Int32)
Instantiate the class indicating the host and the port of a node.
Declaration
public ServerEventsClient(string host, int port)
Parameters
Type | Name | Description |
---|---|---|
System.String | host | IP or domain name of the node. |
System.Int32 | port | Event stream port. |
Fields
_host
Declaration
protected string _host
Field Value
Type | Description |
---|---|
System.String |
_port
Declaration
protected int _port
Field Value
Type | Description |
---|---|
System.Int32 |
Methods
_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 |
AddEventCallback(EventType, String, EventCallback, Int32)
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 = null)
Parameters
Type | Name | Description |
---|---|---|
EventType | eventType | One or more event types to subscribe to. |
System.String | name | Name of the callback. Use it later to remove the callback when needed. |
EventCallback | cb | Callback method to call. |
System.Int32 | startFrom | The minimum Id number in the event stream that we want to receive. |
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. |
System.String | name | Name of the callback. |
Returns
Type | Description |
---|---|
System.Boolean |
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()
StopListening()
Stops listening to the event stream and disconnects from the node.
Declaration
public async Task StopListening()
Returns
Type | Description |
---|---|
Task |
Wait()
Blocks the calling thread until all channels are disconnected.
Declaration
public void Wait()