C# Class SocketIOClient.Client

Class to emulate socket.io javascript client capabilities for .net classes
Connection for wss or https urls
Inheritance: IDisposable, SocketIOClient.IClient
Show file Open project: uken/UnitySocketIO-WebSocketSharp Class Usage Examples

Public Properties

Property Type Description
ConnectionOpenEvent System.Threading.ManualResetEvent
LastErrorMessage string
MessageQueueEmptyEvent System.Threading.ManualResetEvent
MessageQueuePendingEvent System.Threading.ManualResetEvent

Protected Properties

Property Type Description
registrationManager RegistrationManager
uri Uri
wsClient WebSocket

Public Methods

Method Description
Client ( string url ) : System
Close ( ) : void

Close SocketIO4Net.Client and clear all event registrations

Connect ( string endPoint ) : IEndPointClient
Connect ( ) : void

Initiate the connection with Socket.IO service

Dispose ( ) : void
Emit ( string eventName, Object payload ) : void

Asynchronously sends payload using eventName

payload must a string or Json Serializable

Mimicks Socket.IO client 'socket.emit('name',payload);' pattern

Do not use the reserved socket.io event names: connect, disconnect, open, close, error, retry, reconnect

Emit ( string eventName, Object payload, string endPoint, Action callback ) : void

Asynchronously sends payload using eventName

payload must a string or Json Serializable

Mimicks Socket.IO client 'socket.emit('name',payload);' pattern

Do not use the reserved socket.io event names: connect, disconnect, open, close, error, retry, reconnect

ArgumentOutOfRangeException will be thrown on reserved event names

On ( string eventName, Action action ) : void

Asynchronously calls the action delegate on event message notification

Mimicks the Socket.IO client 'socket.on('name',function(data){});' pattern

Reserved socket.io event names available: connect, disconnect, open, close, error, retry, reconnect

On ( string eventName, string endPoint, Action action ) : void
Send ( IMessage msg ) : void

Queue outbound message

Send ( string msg ) : void

Protected Methods

Method Description
Dispose ( bool disposing ) : void
OnConnectionRetryAttemptEvent ( object sender, EventArgs e ) : void
OnErrorEvent ( object sender, ErrorEventArgs e ) : void
OnHeartBeatTimerCallback ( object state ) : void
OnMessageEvent ( IMessage msg ) : void

if a registerd event name is found, don't raise the more generic Message event

OnSocketConnectionClosedEvent ( object sender, EventArgs e ) : void
ReConnect ( ) : void
closeHeartBeatTimer ( ) : void
closeOutboundQueue ( ) : void
closeWebSocketClient ( ) : void
dequeuOutboundMessages ( ) : void

While connection is open, dequeue and send messages to the socket server

requestHandshake ( Uri uri, DownloadStringCompletedEventHandler handshakeCallback ) : void

Client performs an initial HTTP POST to obtain a SessionId (sid) assigned to a client, followed by the heartbeat timeout, connection closing timeout, and the list of supported transports.

The tansport and sid are required as part of the ws: transport connection

Private Methods

Method Description
EndAsyncEvent ( IAsyncResult result ) : void
HandshakeCallback ( object sender, DownloadStringCompletedEventArgs eventArgs ) : void
Send_backup ( string rawEncodedMessageText ) : void
wsClient_Closed ( object sender, WebSocketSharp e ) : void

websocket has closed unexpectedly - retry connection

wsClient_Error ( object sender, WebSocketSharp e ) : void
wsClient_MessageReceived ( object sender, WebSocketSharp e ) : void

Raw websocket messages from server - convert to message types and call subscribers of events and/or callbacks

wsClient_OpenEvent ( object sender, EventArgs e ) : void

Method Details

Client() public method

public Client ( string url ) : System
url string
return System

Close() public method

Close SocketIO4Net.Client and clear all event registrations
public Close ( ) : void
return void

Connect() public method

public Connect ( string endPoint ) : IEndPointClient
endPoint string
return IEndPointClient

Connect() public method

Initiate the connection with Socket.IO service
public Connect ( ) : void
return void

Dispose() public method

public Dispose ( ) : void
return void

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void

Emit() public method

Asynchronously sends payload using eventName

payload must a string or Json Serializable

Mimicks Socket.IO client 'socket.emit('name',payload);' pattern

Do not use the reserved socket.io event names: connect, disconnect, open, close, error, retry, reconnect

public Emit ( string eventName, Object payload ) : void
eventName string
payload Object must be a string or a Json Serializable object
return void

Emit() public method

Asynchronously sends payload using eventName

payload must a string or Json Serializable

Mimicks Socket.IO client 'socket.emit('name',payload);' pattern

Do not use the reserved socket.io event names: connect, disconnect, open, close, error, retry, reconnect

ArgumentOutOfRangeException will be thrown on reserved event names
public Emit ( string eventName, Object payload, string endPoint, Action callback ) : void
eventName string
payload Object must be a string or a Json Serializable object
endPoint string
callback Action
return void

On() public method

Asynchronously calls the action delegate on event message notification

Mimicks the Socket.IO client 'socket.on('name',function(data){});' pattern

Reserved socket.io event names available: connect, disconnect, open, close, error, retry, reconnect

public On ( string eventName, Action action ) : void
eventName string
action Action
return void

On() public method

public On ( string eventName, string endPoint, Action action ) : void
eventName string
endPoint string
action Action
return void

OnConnectionRetryAttemptEvent() protected method

protected OnConnectionRetryAttemptEvent ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void

OnErrorEvent() protected method

protected OnErrorEvent ( object sender, ErrorEventArgs e ) : void
sender object
e ErrorEventArgs
return void

OnHeartBeatTimerCallback() protected method

protected OnHeartBeatTimerCallback ( object state ) : void
state object
return void

OnMessageEvent() protected method

if a registerd event name is found, don't raise the more generic Message event
protected OnMessageEvent ( IMessage msg ) : void
msg IMessage
return void

OnSocketConnectionClosedEvent() protected method

protected OnSocketConnectionClosedEvent ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void

ReConnect() protected method

protected ReConnect ( ) : void
return void

Send() public method

Queue outbound message
public Send ( IMessage msg ) : void
msg IMessage
return void

Send() public method

public Send ( string msg ) : void
msg string
return void

closeHeartBeatTimer() protected method

protected closeHeartBeatTimer ( ) : void
return void

closeOutboundQueue() protected method

protected closeOutboundQueue ( ) : void
return void

closeWebSocketClient() protected method

protected closeWebSocketClient ( ) : void
return void

dequeuOutboundMessages() protected method

While connection is open, dequeue and send messages to the socket server
protected dequeuOutboundMessages ( ) : void
return void

requestHandshake() protected method

Client performs an initial HTTP POST to obtain a SessionId (sid) assigned to a client, followed by the heartbeat timeout, connection closing timeout, and the list of supported transports.

The tansport and sid are required as part of the ws: transport connection

protected requestHandshake ( Uri uri, DownloadStringCompletedEventHandler handshakeCallback ) : void
uri Uri http://localhost:3000
handshakeCallback DownloadStringCompletedEventHandler
return void

Property Details

ConnectionOpenEvent public property

Connection Open Event
public ManualResetEvent,System.Threading ConnectionOpenEvent
return System.Threading.ManualResetEvent

LastErrorMessage public property

Value of the last error message text
public string LastErrorMessage
return string

MessageQueueEmptyEvent public property

ResetEvent for Outbound MessageQueue Empty Event - all pending messages have been sent
public ManualResetEvent,System.Threading MessageQueueEmptyEvent
return System.Threading.ManualResetEvent

MessageQueuePendingEvent public property

ResetEvent for Outbound MessageQueue Pending Messages Event - there are pending messages ready to send
public ManualResetEvent,System.Threading MessageQueuePendingEvent
return System.Threading.ManualResetEvent

registrationManager protected property

RegistrationManager for dynamic events
protected RegistrationManager registrationManager
return RegistrationManager

uri protected property

Uri of Websocket server
protected Uri uri
return Uri

wsClient protected property

Underlying WebSocket implementation
protected WebSocket wsClient
return WebSocket