UDP Server
Overview
The UDP server is one of the three real-time communication servers provided by Diarkis.
It can expose built-in commands of pre-prepared modules to clients, as well as implement and expose custom commands.
A command is a formatted packet sent from the client and processed by the server. Using commands, the Diarkis server cluster interacts with the client.
Setting Up the UDP Server
To expose built-in commands to the client, you can set up using the diarkisexec
package.
You can expose built-in commands by specifying the module with
diarkisexec.SetupDiarkis()
. Customize the configuration by specifying theConfigPath
of each module.You can expose custom commands with
diarkisexec.SetServerCommandHandler()
.You can set up the UDP server with
diarkisexec.SetupDiarkisUDPServer()
. Customize the server settings with a JSON file passed as an argument.
⚠️ The above functions must be executed before calling
diarkisexec.StartDiarkis()
.
For more details, refer to the diarkisexec API reference.
Mesh Configuration
Specify the path to the JSON file in meshConfigPath
. For more details, refer to #mesh-she-ding.
UDP Server Configuration
The configuration is written in JSON.
Key | Default | Description |
---|---|---|
enableP2P | true | When set to true, the client can obtain its public address for P2P. |
address | "127.0.0.1" | The address to bind the UDP server to. |
nic | "eth0" | The interface name for obtaining the address. Used when the address is not specified. |
port | "7100" | The port for the UDP server to bind to. The UDP server will automatically find available ports starting from the specified port. |
connectionTTL | 10 | The TTL of the connection. If this time is exceeded, the client will be disconnected from the server. |
sendUDPInterval | 0 | The interval (in milliseconds) for sending UDP packets. If set below 10, sent packets will not be buffered. |
handleRUDPInterval | 100 min: 10 | The interval (in milliseconds) for sending and receiving RUDP packets. The smaller the value, the more responsive (faster) the server will be, but at the cost of increased CPU load. |
retryInterval | 1000 | The retry interval (in milliseconds) for RUDP packets. |
maxRetry | 10 | The maximum number of retries for RUDP packets. If this value is exceeded, the RUDP connection is considered timed out and discarded. |
rcvWorkers | Number of CPU cores | The number of goroutines for receiving UDP packets. |
enableEncryption | true | If set to false, packet encryption and decryption will be disabled. A similar configuration is required for the HTTP server. |
⚠️ In cloud environments, set
address
to the private IP address and use the environment variableDIARKIS_CLOUD_ENV
.
For more details, refer to the server API reference.
Last updated