|
delegate void | OfflineHandler () |
|
delegate void | PacketHandler (byte[] packet, string senderAddress) |
|
delegate void | ResponseHandler (uint ver, uint cmd, uint status, byte[] payload, bool reliable) |
|
delegate void | PushHandler (uint ver, uint cmd, byte[] payload, bool reliable) |
|
delegate void | EchoHandler (double echoTime, string myAddress) |
|
delegate void | PingHandler (double pingTime, string myAddress) |
|
delegate void | ConnectHandler (int status, bool reconnected) |
|
delegate void | DisconnectHandler (bool reconnecting) |
|
delegate void | ExceptionHandler (int errCode, string errMsg) |
|
delegate void | ResetHandler () |
|
delegate void | AddressChangeHandler (string oldAddr, string newAddr) |
|
delegate void | NotificationHandler (uint ver, uint cmd, byte[] message) |
|
| Udp (int sendInterval=0, int echoInterval=5000) |
| Initializes an instance of . More...
|
|
void | EnableSendImmediate () |
| Enables UDP messages to be sent immediately instead of being bufferred. More...
|
|
string | GetServerEndPoint () |
| Returns the server endpoint that the client is conencted to as a string. More...
|
|
int | GetDisconnectionReason () |
| Returns the cause of disconnection as enum DISCONN_EXPECTED Disconnection was expected and there was no error DISCONN_NO_RESPONSE Could not get a response from the server DISCONN_RETRY_TIMEOUT RUDP retries took too long More...
|
|
void | SetClientKey (string clientKey) |
| Sets up client key and send it to the server on connection. More...
|
|
void | SetEchoTimeout (double timeoutInMilliseconds) |
| Sets echo timeout in milliseconds. More...
|
|
void | SetEncryptionKeys (byte[] sid, byte[] key, byte[] iv, byte[] mackey) |
| Sets up encryption and decryption of packets. 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. Udp.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) turned on. Udp.OnConnect will be invoked if connection is successfully made. When connected to the server with this method, P2P is disabled. More...
|
|
void | Reset () |
| Remove all event listeners and triggers an even Udp.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 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 | Disconnect () |
| Disconnects from the server the client is connected to and triggers Udp.OnDisconnect. OnDisconnect event will be raised when Disconnect is successful. More...
|
|
string | GetAddress () |
| Returns the client's external address as a string. This is shared with other client(s) for class for peer-to-peer communication. More...
|
|
List< string > | GetLocalAddress () |
| Returns a list of local address and port More...
|
|
void | RSend (uint ver, uint cmd, byte[] payload) |
| Sends a packet as an RUDP (Reliable UDP) packet that is guaranteed its delivery to the server. More...
|
|
void | RSend (uint ver, uint cmd, byte[] payload, int payloadLength) |
| Sends a packet as an RUDP (Reliable UDP) packet that is guaranteed its delivery to the server. More...
|
|
void | Send (uint ver, uint cmd, byte[] payload) |
| Sends a packet as a plain UDP packet. The packet maybe lost. More...
|
|
void | Send (uint ver, uint cmd, byte[] payload, int payloadLength) |
| Sends a packet as a plain UDP packet. The packet maybe lost. More...
|
|
void | Migrate () |
| Migrate to a new server node. Useful when handling OnOffline event. OnConnect event with reconnected = true will be raised 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 | Echo () |
| Immediately sends an echo packet. Echo packets are sent as RUDP packets. More...
|
|
void | Ping () |
| Sends a ping packet. Ping packets are sent as UDP packets. Raises OnPing event. If the packet is lost, however, OnPing event will not be raised. More...
|
|
void | Update () |
| Must be called a certain interval from the main thread. For Unity application this must be called in Update. More...
|
|
void | SendTo (byte[] msg, IPEndPoint ip) |
| Sends a UDP packet to a specified target IP end point More...
|
|
void | Dispose () |
|
|
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 | MAX_PACKET_SIZE = 1300 |
| Actual max size of a UDP packet is 65507 but we set the value to be lower. Typically a UDP packet that is beigger than 1400 bytes starts to split increasing the chance of packet loss. More...
|
|
const int | DISCONN_INIT = -1 |
| Disconnection reason enums. This is the initial reason state. More...
|
|
const int | DISCONN_EXPECTED = 0 |
| Disconnection reason enums. This indicates the disconnect was intentional and expected. More...
|
|
const int | DISCONN_NO_RESPONSE = 1 |
| Disconnection reason enums. Indicates that the disconnect was instructed by the server. The server has discarded the client connection state. This usually means that the client was not responsive to the server. More...
|
|
const int | DISCONN_RETRY_TIMEOUT = 2 |
| Disconnection reason enums. Indicates the RUDP retries have timedout. More...
|
|
const int | DISCONN_FORCED = 3 |
| Disconnection reason enums. This is not used internally. Reserved for forced disconnection. 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...
|
|
|
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) |
|
|
OfflineHandler | OnOffline |
| The event raised when the connected server is ready to shutdown. The client is recommanded to either re-connect or disconnect. More...
|
|
PacketHandler | OnPacket |
| The event raised when inbound packet is ready. This event is intended for internal use only. More...
|
|
ResponseHandler | OnResponse |
| The event raised when a server response has been received. This event is raised for both reliable and unreliable (UDP and RUDP). More...
|
|
EchoHandler | OnEcho |
| The event faised when a response of an echo has been received. The event passes the traveling time of an echo and the client's public address. The client public addess is used for P2P. NOTE: Echo is sent and received as RUDP. More...
|
|
PingHandler | OnPing |
| The event raised by a response of a ping has been received. Ping behaves similar to echo, but it is handled as UDP. More...
|
|
PushHandler | OnPush |
| The event raised when server push has been received. This event is raised for both reliable and unreliable (UDP and RUDP). 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...
|
|
ExceptionHandler | OnException |
| The event raised when a socket exception is caught. More...
|
|
ResetHandler | OnReset |
| The event raised when is invoked to reset all event listeners. This event is meant for internal use. More...
|
|
AddressChangeHandler | OnAddressChange |
| The event is raised when client public address has changed. More...
|
|
NotificationHandler | OnNotification |
| The event raised when the client receives a server notification. More...
|
|
UDP client for Diarkis server that handles UDP messaging and RUDP messages. The class receives messages from the server via event callbacks.
UDP Packet Structure: Below is the break down of a UDP/RUDP packet data strcuture. Endianesss is Big Endian. Packet size over head:
Header and security data | 66 byte |
Encryption padding | 0 ~ 15 byte |
Payload size | N byte |
UDP/RUDP Packet
SID | Mac Key | Original Packet Size | Padding | Encrypted Data |
16 byte | 32 byte | 4 byte | 0 ~ 15 byte | N byte |
Encrypted Data
Symbol | Packet Size + Command Ver | Command ID | UPD Type | Payload |
4 byte | 4 byte | 2 byte | 4 byte | N byte |