![]() |
Diarkis C# Client SDK
|
Public Member Functions | |
delegate void | HeartbeatHandler () |
delegate void | OfflineHandler () |
delegate void | ExceptionHandler (int errCode, string errMsg) |
delegate void | ConnectHandler (int status, bool reconnected) |
delegate void | DisconnectHandler (bool reconnecting) |
delegate void | PushHandler (uint ver, uint cmd, byte[] payload, bool notused) |
delegate void | ResponseHandler (uint ver, uint cmd, uint status, byte[] payload, bool notused) |
delegate void | ResetHandler () |
delegate void | NotificationHandler (uint ver, uint cmd, byte[] message) |
Tcp (int heartbeatInterval=5000) | |
Initializes a new instance of Tcp class. More... | |
void | SetNoDelay (bool noDelay) |
Disables Nagle's algorithm of TCP if noDelay is set to true. Disabling Nable's algorithm will change the behavior of TCP not to use buffer when sending packets giving it less delay, of ppacket delivery, but comes with a cost of higher CPU usage. 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... | |
string | GetServerEndPoint () |
Returns the server endpoint that the client is conencted to as a string. More... | |
bool | IsConnected () |
Returns true if the client is connected to the server. More... | |
void | Connect (string addr, int port, double timeout=1000) |
Attemps to connect to the server. Tcp.OnConnect will be invoked if connection is successfully made. More... | |
void | ConnectDualMode (string addr, int port, double timeout=1000) |
Attemps to connect to the server using socket dual mode (explicit support for IPv6). Tcp.OnConnect will be invoked if connection is successfully made. More... | |
void | Reset () |
Remove all event listeners and triggers an even Tcp.OnReset. This method MUST be called from the main thread ONLY. More... | |
void | CatchOnReconnect (Action< bool > action, uint ver, uint cmd, uint timeout=CATCH_RECONN_WAIT) |
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 | Reconnect (string tcpAddr, int tcpPort) |
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 | Disconnect () |
Disconnects from the server the client is connected to and triggers Tcp.OnDisconnect. OnDisconnect event will be raised when Disconnect is succuessful. More... | |
void | Send (uint ver, uint cmd, byte[] payload) |
Sends a packet as a command to the server. More... | |
void | Send (uint ver, uint cmd, byte[] payload, int payloadLength) |
Sends a packet as a command to the server. More... | |
void | Heartbeat () |
Immediately sends a heartbeat packet to the server. Heartbeat is invoked internally at a fixed interval. By default the interval is 5 seconds. More... | |
void | Migrate () |
Migrate to a new server node. Useful when handling OnOffline event. The current server session and encryption keys will be securely carried over. OnConnect event with reconnected = true will be raised. NOTE: This method does not require Auth from Diarkis HTTP server. More... | |
void | Migrate (string serverType) |
Migrate to a new server node. Useful when handling OnOffline event. The current server session and encryption keys will be securely carried over. OnConnect event with reconnected = true will be raised New server node is decided within the server type given. NOTE: This method does not require Auth from Diarkis HTTP server. More... | |
void | Update () |
Must be called a certain interval from the main thread. This must be kept until termination of the application. For Unity application, this must be called in Update. More... | |
![]() | |
void | Dispose () |
Static Public Attributes | |
const uint | STATUS_OK = 1 |
Command response status that indicates command execution on the server was successful. More... | |
const uint | STATUS_BAD = 4 |
Command response status that indicates command execution on the server failed. The error indicates the cause of the failure is client inputs. More... | |
const uint | STATUS_ERR = 5 |
Command response status that indicates command execution on the server failed. The error indicates the cause of the failure is the server. More... | |
![]() | |
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... | |
Protected Member Functions | |
override void | Dispose (bool disposing) |
![]() | |
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) |
Events | |
HeartbeatHandler | OnHeartbeat |
The event raised when a response of HeartBeat. More... | |
OfflineHandler | OnOffline |
The event raised when the connected server is ready to shutdown. The client is recommanded to either re-connect or disconnect. More... | |
ExceptionHandler | OnException |
The event raised when a socket exception is caught. More... | |
ConnectHandler | OnConnect |
The event raised when successful connection to the server is made by . The argument reconnecting indicates either re-connect or connect. More... | |
DisconnectHandler | OnDisconnect |
The event raised when disconnect from the server has been completed. More... | |
PushHandler | OnPush |
The event raised when server push has been received. More... | |
ResponseHandler | OnResponse |
The event raised when a server response has been received. More... | |
ResetHandler | OnReset |
The event raised when is invoked to reset all event listeners. This event is meant for internal use. More... | |
NotificationHandler | OnNotification |
The event raised when the client receives a server push with ver=0 cmd=400. More... | |
Additional Inherited Members | |
![]() | |
static string | GetVersion () |
![]() | |
bool | IsDualMode = false |
|
inline |
Initializes a new instance of Tcp class.
heartbeatInterval | Interval in milliseconds to send "heartbeat" packet to server. Default is 5000 milliseconds. If you change heartbeatInterval, you also need to change the configuration for the server accordingly. |
|
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.
action | Callback function. |
ver | Command version of response to trigger the event |
cmd | Command ID of response to trigger the event |
timeout | OnJoin trigger timeout in milliseconds to control when OnJoin is raised when there is no internal reconnect. Default is 1000ms. |
|
inline |
Attemps to connect to the server. Tcp.OnConnect will be invoked if connection is successfully made.
addr | TCP server address (hostname) to connect to. |
port | TCP server port to connect to. |
timeout | Connection timeout in milliseconds. /param> |
|
inline |
Attemps to connect to the server using socket dual mode (explicit support for IPv6). Tcp.OnConnect will be invoked if connection is successfully made.
addr | TCP server address (hostname) to connect to. |
port | TCP server port to connect to. |
|
inline |
Disconnects from the server the client is connected to and triggers Tcp.OnDisconnect. OnDisconnect event will be raised when Disconnect is succuessful.
|
inline |
Returns the server endpoint that the client is conencted to as a string.
|
inline |
Immediately sends a heartbeat packet to the server. Heartbeat is invoked internally at a fixed interval. By default the interval is 5 seconds.
|
inline |
Returns true if the client is connected to the server.
|
inline |
Migrate to a new server node. Useful when handling OnOffline event. The current server session and encryption keys will be securely carried over. OnConnect event with reconnected = true will be raised. NOTE: This method does not require Auth from Diarkis HTTP server.
|
inline |
Migrate to a new server node. Useful when handling OnOffline event. The current server session and encryption keys will be securely carried over. OnConnect event with reconnected = true will be raised New server node is decided within the server type given. NOTE: This method does not require Auth from Diarkis HTTP server.
|
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.
tcpAddr | TCP server address (hostname) to connect to. |
tcpPort | TCP server port to connect to. |
|
inline |
Remove all event listeners and triggers an even Tcp.OnReset. This method MUST be called from the main thread ONLY.
|
inline |
Sends a packet as a command to the server.
ver | Command version that is defined on the server. |
cmd | Command ID that is defined on the server. |
payload | Command payload. |
|
inline |
Sends a packet as a command to the server.
ver | Command version that is defined on the server. |
cmd | Command ID that is defined on the server. |
payload | Command payload. |
payloadLength | Manually given command payload length. |
|
inline |
Sets up client key and send it to the server on connection.
clientKey | Client key to be sent to the server. Client key must match on the server or connection will be terminated. |
|
inline |
Sets up encryption and decryption of packets.
sid | Session ID that is valid until connection is disconnected. |
key | Encryption key. |
iv | Encryption initialization vector (IV). |
mackey | Mac key used sign encrypted payload of a packet. |
|
inline |
Disables Nagle's algorithm of TCP if noDelay is set to true. Disabling Nable's algorithm will change the behavior of TCP not to use buffer when sending packets giving it less delay, of ppacket delivery, but comes with a cost of higher CPU usage.
noDelay | Disables Nagle's algorithm if true. |
|
inline |
Must be called a certain interval from the main thread. This must be kept until termination of the application. For Unity application, this must be called in Update.
|
static |
Command response status that indicates command execution on the server failed. The error indicates the cause of the failure is client inputs.
|
static |
Command response status that indicates command execution on the server failed. The error indicates the cause of the failure is the server.
|
static |
Command response status that indicates command execution on the server was successful.
ConnectHandler Diarkis.Tcp.OnConnect |
The event raised when successful connection to the server is made by . The argument reconnecting indicates either re-connect or connect.
DisconnectHandler Diarkis.Tcp.OnDisconnect |
The event raised when disconnect from the server has been completed.
ExceptionHandler Diarkis.Tcp.OnException |
The event raised when a socket exception is caught.
HeartbeatHandler Diarkis.Tcp.OnHeartbeat |
The event raised when a response of HeartBeat.
NotificationHandler Diarkis.Tcp.OnNotification |
The event raised when the client receives a server push with ver=0 cmd=400.
OfflineHandler Diarkis.Tcp.OnOffline |
The event raised when the connected server is ready to shutdown. The client is recommanded to either re-connect or disconnect.
PushHandler Diarkis.Tcp.OnPush |
The event raised when server push has been received.
ResetHandler Diarkis.Tcp.OnReset |
The event raised when is invoked to reset all event listeners. This event is meant for internal use.
ResponseHandler Diarkis.Tcp.OnResponse |
The event raised when a server response has been received.