Diarkis C# Client SDK
Public Member Functions | Protected Member Functions | Protected Attributes | Events | List of all members
Diarkis.Ws Class Reference
Inheritance diagram for Diarkis.Ws:
Diarkis.Core

Public Member Functions

delegate void OnConnectHandler (bool success, bool reconnected)
 
delegate void OnDisconnectHandler (bool reconnecting)
 
delegate void OnMessageHandler (uint ver, uint cmd, string data)
 
delegate void OnHeartbeatHandler ()
 
delegate void OnOfflineHandler ()
 
delegate void OnResetHandler ()
 
delegate void OnExceptionHandler (int errCode, string errMessage)
 
 Ws (int hbInterval=5000)
 Initializes a new instance of Ws class. More...
 
void Update ()
 Must be called a certain interval from the main thread. For Unity application this must be called in Update. More...
 
void SetEncryptionKeys (byte[] sid, byte[] key, byte[] iv, byte[] mackey)
 Sets up encryption and decryption of packets. More...
 
void SetClientKey (string clientKey)
 Sets up client key and send it to the server on connection. More...
 
bool IsConnected ()
 Returns true if WebSocket client is connected to the server. More...
 
void Connect (string addr, int port, string uri)
 Creates a new WebSocket connection to the server. More...
 
void Disconnect ()
 Closes the WebSocket connection. Raises OnDisconnect event. More...
 
void Migrate ()
 Migrate to a new server node. Useful when handling OnOffline event. OnConnect event with reconnected = true will be raised. The current server session and encryption keys will be securely carried over. More...
 
void Reconnect (string addr, int port)
 IMPORTANT: This is internal use ONLY. Reconnects to the server. The server MUST be different from the one the client is currently connected to. More...
 
void CatchOnReconnect (Action< bool > action, uint ver, uint cmd)
 Registers a callback function to be triggered when the client is re-connected and a command response of ver and cmd is returned. Unlike other events, you must use this just before invoking a method that would trigger this event. This event is raised only once. You must call this again if you need this event again. More...
 
void Reset ()
 Remove all event listeners and triggers an even Ws.OnReset. This method MUST be called from the main thread ONLY. More...
 
void Send (uint ver, uint cmd, string data)
 Sends a byte array message that is JSON encoded to the server. More...
 
bool FindBoolValueByKeyFromJSON (string json, string key)
 
int FindNumericValueByKeyFromJSON (string json, string key)
 
string FindStringValueByKeyFromJSON (string json, string key)
 
string FindObjectValueByKeyFromJSON (string json, string key)
 
string FindArrayValueByKeyFromJSON (string json, string key)
 
string GetDataFromJSON (string data)
 
byte[] GetBytesFromEncodedString (string encoded)
 
- Public Member Functions inherited from Diarkis.Core
void Dispose ()
 

Protected Member Functions

override void Dispose (bool disposing)
 
- Protected Member Functions inherited from Diarkis.Core
void NewTCP (string addr, int port)
 
void NewTCPDualMode (string addr, int port)
 
void ConnectTCP (string addr, int port)
 
void CloseTCP ()
 
NetworkStream GetTCPStream ()
 
void SetTCPNoDelay (bool noDelay)
 
bool IsTCPConnected ()
 
int GetTCPAvailable ()
 
void ConnectUDP (string addr, int port)
 
void ConnectUDPDualMode (string addr, int port)
 
void CloseUDP ()
 
bool IsUDPConnected ()
 
bool UDPPolling (int pollingTime)
 
int GetUDPAvailable ()
 
string FindLocalAddress (IPAddress ip)
 
int UDPRcvFrom (byte[] buff, ref EndPoint ep)
 
void SendUDP (byte[] msg, int length)
 
void SendUDPTo (byte[] msg, int length, IPEndPoint ip)
 
IPEndPoint GetRemoteIP ()
 
EndPoint GetConnetedUDPEndPoint ()
 
IPAddress GetIPAddress_ (string addr, int port)
 

Protected Attributes

int maxMessageSize = 6000
 
int networkThreadSleepTime = 10
 
- Protected Attributes inherited from Diarkis.Core
bool IsDualMode = false
 

Events

OnConnectHandler OnConnect
 
OnDisconnectHandler OnDisconnect
 
OnMessageHandler OnMessage
 
OnHeartbeatHandler OnHeartbeat
 
OnOfflineHandler OnOffline
 
OnResetHandler OnReset
 
OnExceptionHandler OnException
 

Additional Inherited Members

- Static Public Member Functions inherited from Diarkis.Core
static string GetVersion ()
 
- Static Public Attributes inherited from Diarkis.Core
const int CONN_TIMEOUT = -1
 Status of OnConnect event. This status indicates the connection has timedout. More...
 
const int CONN_ERR = -2
 Status of OnConnect event. This status indicates the failure of opening a TCP socket. More...
 
const int CONN_SUCCESS = 0
 Status of OnConnect event. This status indicates the connection has been successfully established. More...
 

Constructor & Destructor Documentation

◆ Ws()

Diarkis.Ws.Ws ( int  hbInterval = 5000)
inline

Initializes a new instance of Ws class.

Parameters
hbIntervalInterval in milliseconds to send "heartbeat" packet to server. Default is 5000 milliseconds.

Member Function Documentation

◆ CatchOnReconnect()

void Diarkis.Ws.CatchOnReconnect ( Action< bool >  action,
uint  ver,
uint  cmd 
)
inline

Registers a callback function to be triggered when the client is re-connected and a command response of ver and cmd is returned. Unlike other events, you must use this just before invoking a method that would trigger this event. This event is raised only once. You must call this again if you need this event again.

Parameters
actionCallback function.
verCommand version of response to trigger the event
cmdCommand ID of response to trigger the event

◆ Connect()

void Diarkis.Ws.Connect ( string  addr,
int  port,
string  uri 
)
inline

Creates a new WebSocket connection to the server.

Parameters
addrServer endpoint address for the client to connect to.

◆ Disconnect()

void Diarkis.Ws.Disconnect ( )
inline

Closes the WebSocket connection. Raises OnDisconnect event.

◆ IsConnected()

bool Diarkis.Ws.IsConnected ( )
inline

Returns true if WebSocket client is connected to the server.

◆ Migrate()

void Diarkis.Ws.Migrate ( )
inline

Migrate to a new server node. Useful when handling OnOffline event. OnConnect event with reconnected = true will be raised. The current server session and encryption keys will be securely carried over.

◆ Reconnect()

void Diarkis.Ws.Reconnect ( string  addr,
int  port 
)
inline

IMPORTANT: This is internal use ONLY. Reconnects to the server. The server MUST be different from the one the client is currently connected to.

Parameters
addrWebSocket server address (hostname) to connect to.
portWebSocket server port to connect to.

◆ Reset()

void Diarkis.Ws.Reset ( )
inline

Remove all event listeners and triggers an even Ws.OnReset. This method MUST be called from the main thread ONLY.

◆ Send()

void Diarkis.Ws.Send ( uint  ver,
uint  cmd,
string  data 
)
inline

Sends a byte array message that is JSON encoded to the server.

Parameters
verCommand version
cmdCommand ID
dataMessage data as a string

◆ SetClientKey()

void Diarkis.Ws.SetClientKey ( string  clientKey)
inline

Sets up client key and send it to the server on connection.

Parameters
clientKeyClient key to be sent to the server. Client key must match on the server or connection will be terminated.

◆ SetEncryptionKeys()

void Diarkis.Ws.SetEncryptionKeys ( byte[]  sid,
byte[]  key,
byte[]  iv,
byte[]  mackey 
)
inline

Sets up encryption and decryption of packets.

Parameters
sidSession ID that is valid until connection is disconnected.
keyEncryption key.
ivEncryption initialization vector (IV).
mackeyMac key used sign encrypted payload of a packet.

◆ Update()

void Diarkis.Ws.Update ( )
inline

Must be called a certain interval from the main thread. For Unity application this must be called in Update.


The documentation for this class was generated from the following file: