Protocol Network
Binary UDP protocol with token authentication
To enhance security and identification, a unique token is sent to the client during the initial connection via TCP. This token must be included in each UDP message sent by the client to the server to validate the sender’s identity.
Structure of the message
Each message sent via UDP is encapsulated in a package structured as follows:
Header (12 bytes)
Version (1 byte): Protocol version
Message type (1 byte): Identifying the message type
Client to Server:
0x01 -> Arrow Key
0x02 -> Alpha Key
0x03 -> Number Key
0x04 -> Special Key
0x05 -> Error Message
Message ID (2 bytes): Unique message identifier to allow detection of duplicates or late messages.
Token (4 bytes): Client ID token. This token is generated by the server during the initial connection. If the message is sent by the server the Token will be ffffffff
Payload length (4 bytes): The length of the message data (payload), in bytes.
Payload (depend of the Message type)
Contains data specific to the type of message
Message Type Client -> Server:
If message type is 0x01 (Arrow Key):
0x01 -> Up key
0x02 -> Right key
0x03 -> Down key
0x04 -> Left key
If message type is 0x02 (Alpha Key):
0x01 -> 'A' key
0x02 -> 'B' key
0x03 -> 'C' key
0x04 -> 'D' key
0x05 -> 'E' key
0x06 -> 'F' key
0x07 -> 'G' key
0x08 -> 'H' key
0x09 -> 'I' key
0x0A -> 'J' key
0x0B -> 'K' key
0x0C -> 'L' key
0x0D -> 'M' key
0x0E -> 'N' key
0x0F -> 'O' key
0x10 -> 'P' key
0x11 -> 'Q' key
0x12 -> 'R' key
0x13 -> 'S' key
0x14 -> 'T' key
0x15 -> 'U' key
0x16 -> 'V' key
0x17 -> 'W' key
0x18 -> 'X' key
0x19 -> 'Y' key
0x1A -> 'Z' key
Message Type: 0x03 (Number Key):
0x01 -> '1' key
0x02 -> '2' key
0x03 -> '3' key
0x04 -> '4' key
0x05 -> '5' key
0x06 -> '6' key
0x07 -> '7' key
0x08 -> '8' key
0x09 -> '9' key
0x0A -> '0' key
Message Type: 0x04 (Special Key)
0x01 -> Space key
0x02 -> Enter key
0x03 -> Escape key
0x04 -> Backspace key
0x05 -> Tab key
0x06 -> Shift key
0x07 -> Control key
0x08 -> Alt key
0x09 -> Caps Lock key
0x0A -> F1 key
0x0B -> F2 key
0x0C -> F3 key
0x0D -> F4 key
0x0E -> F5 key
0x0F -> F6 key
0x10 -> F7 key
0x11 -> F8 key
0x12 -> F9 key
0x13 -> F10 key
0x14 -> F11 key
0x15 -> F12 key
Checksum (2 octets) :
Used to check data integrity. The checksum is calculated on the whole packet (header + payload) using a simple checksum
Exemple:
Header (12 bytes):
Version:
0x01(1 byte)Message type:
0x02(1 byte)Message ID:
0x0001(2 bytes)Token:
0xDEADBEEF(4 bytes)Payload length:
0x00000001(4 bytes)
Payload (1 byte):
Payload:
0x17(W key)
Checksum (2 bytes):
Suppose the checksum calculates to
0xF0F0.
Final packet:
01 02 00 01 DE AD BE EF 00 00 00 01 17 F0 F0
This packet represents a client with token 0xDEADBEEF sending a UDP message indicating that the 'W' key has been pressed.