Class RealtimeSocket
Socket connection handler.
public class RealtimeSocket : IDisposable, IRealtimeSocket, IGettableHeaders
- Inheritance
-
RealtimeSocket
- Implements
- Inherited Members
Constructors
RealtimeSocket(string, ClientOptions)
Initializes this Socket instance.
public RealtimeSocket(string endpoint, ClientOptions options)
Parameters
endpoint
stringoptions
ClientOptions
Properties
GetHeaders
An executable Func
that returns a dictionary of headers to be appended onto a request.
public Func<Dictionary<string, string>>? GetHeaders { get; set; }
Property Value
IsConnected
Returns whether or not the connection is alive.
public bool IsConnected { get; }
Property Value
Methods
AddErrorHandler(ErrorEventHandler)
Adds an error event handler.
public void AddErrorHandler(IRealtimeSocket.ErrorEventHandler handler)
Parameters
handler
IRealtimeSocket.ErrorEventHandler
AddHeartbeatHandler(HeartbeatEventHandler)
Adds a listener to be notified when a message is received.
public void AddHeartbeatHandler(IRealtimeSocket.HeartbeatEventHandler handler)
Parameters
handler
IRealtimeSocket.HeartbeatEventHandler
AddMessageReceivedHandler(MessageEventHandler)
Adds a listener to be notified when a message is received.
public void AddMessageReceivedHandler(IRealtimeSocket.MessageEventHandler handler)
Parameters
handler
IRealtimeSocket.MessageEventHandler
AddStateChangedHandler(StateEventHandler)
Adds a listener to be notified when the socket state changes.
public void AddStateChangedHandler(IRealtimeSocket.StateEventHandler handler)
Parameters
handler
IRealtimeSocket.StateEventHandler
ClearErrorHandlers()
Clears Error Event Handlers
public void ClearErrorHandlers()
ClearHeartbeatHandlers()
Clears all of the listeners from receiving event state changes.
public void ClearHeartbeatHandlers()
ClearMessageReceivedHandlers()
Clears all of the listeners from receiving event state changes.
public void ClearMessageReceivedHandlers()
ClearStateChangedHandlers()
Clears all of the listeners from receiving event state changes.
public void ClearStateChangedHandlers()
Connect()
Connects to a socket server and registers event listeners.
public Task Connect()
Returns
Disconnect(WebSocketCloseStatus, string)
Disconnects from the socket server.
public void Disconnect(WebSocketCloseStatus code = WebSocketCloseStatus.NormalClosure, string reason = "")
Parameters
code
WebSocketCloseStatusreason
string
GetLatency()
Returns the latency (in millis) of roundtrip time from socket to server and back.
public Task<double> GetLatency()
Returns
MakeMsgRef()
Generates an incrementing identifier for message references - this reference is used to coordinate requests with their responses.
public string MakeMsgRef()
Returns
Push(SocketRequest)
Pushes formatted data to the socket server.
If the connection is not alive, the data will be placed into a buffer to be sent when reconnected.
public void Push(SocketRequest data)
Parameters
data
SocketRequest
RemoveErrorHandler(ErrorEventHandler)
Removes an error event handler
public void RemoveErrorHandler(IRealtimeSocket.ErrorEventHandler handler)
Parameters
handler
IRealtimeSocket.ErrorEventHandler
Exceptions
RemoveHeartbeatHandler(HeartbeatEventHandler)
Removes a specified listener from messages received.
public void RemoveHeartbeatHandler(IRealtimeSocket.HeartbeatEventHandler handler)
Parameters
handler
IRealtimeSocket.HeartbeatEventHandler
RemoveMessageReceivedHandler(MessageEventHandler)
Removes a specified listener from messages received.
public void RemoveMessageReceivedHandler(IRealtimeSocket.MessageEventHandler handler)
Parameters
handler
IRealtimeSocket.MessageEventHandler
RemoveStateChangedHandler(StateEventHandler)
Removes a specified listener from socket state changes.
public void RemoveStateChangedHandler(IRealtimeSocket.StateEventHandler handler)
Parameters
handler
IRealtimeSocket.StateEventHandler
ReplyEventName(string)
Returns the expected reply event name based off a generated message ref.
public string ReplyEventName(string msgRef)
Parameters
msgRef
string