The event is raised when a connection is successfully established.
OnException is raised if the connection establishment fails.
tcp.OnCreate+= OnTcpCreate;privatevoidOnTcpCreate( bool reconnected){ // A connection is successfully established. Now you may interactive wit the server cluster}
TCP Client Event - OnException
The event is raised when an exception is caught internally or the Connect method fails.
tcp.OnException+= OnTcpException;privatevoidOnTcpException( int errorCode,string errorMessage){ // Handle the exception here}
TCP Client Event - OnHeartbeat
TCP client sends and receives a heartbeat packet at a certain interval (Default every 5 seconds) to keep the connection “alive”. The event is raised when the client receives a response back from the server cluster.
tcp.OnHeartbeat+= OnTcpHeartbeat;privatevoidOnTcpHeartbeat(){ // Do something if you would like to}
TCP Client Event - OnOffline
The event is raised when the connected server is preparing to go offline. The client is recommended to terminate the current connection and re-establish a new connection when this event is raised.
tcp.OnOffline+= OnTcpOffline;tcp.OnDisconnect+= OnTcpDisconnect;privatevoidOnTcpOffline(){// We set a flag, so we can perform re-connection in OnDisconnect event listenerreconnectFlag =true;// This is raise OnDisconnect eventtcp.Disconnect();}// bool reconnecting is set to true when you use tcp.Reconnect()privatevoidOnTcpDisconnect( bool reconnecting){if (reconnectFlag){ // Call the application server to indirectly obtain a new endpoint here // Assuming we have the new endpoint, we proceed with reconnecttcp.SetEncryptionKeys(newSid, newKey, newIv, newMacKey);tcp.Connect(newAddr, newPort);}}
TCP Event - OnDisconnect
The event is raised when the client successfully disconnects from Diarkis server cluster.
tcp.OnDisconnect+= OnTcpDisconnect;privatevoidOnTcpDisconnect( bool reconnecting){// bool reconnecting is set to true only when tcp.Reconnect() is used.}
TCP Event - OnPush
The event is raised when the client receives a packet as a push (packets that are not requested by the client) from Diarkis server cluster.
tcp.OnPush+= OnTcpPush;privatevoidOnTcpPush( uint ver,uint cmd,byte[] payload){ // Consume payload accordingly using uint ver and cmdswitch(ver) {caseMY_CUSTOM_CMD_VER1:HandleCustomCmdVer1(cmd, payload);default: // Unknown command version... :(break; }}privatevoidHandleCustomCmdVer1( uint cmd,byte[] payload){switch(cmd) {caseCMD1:HandleCmd1(payload);break; }}