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 a 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 clients, you can set up using the diarkisexec
package.
With
diarkisexec.SetupDiarkis()
, you can specify modules to expose built-in commands. You can customize the configuration by specifying theConfigPath
for each module.You can expose custom commands using
diarkisexec.SetServerCommandHandler()
.You can set up the UDP server with
diarkisexec.SetupDiarkisUDPServer()
. Use a JSON file as an argument to customize server settings.
⚠️ The functions above must be executed before calling
diarkisexec.StartDiarkis()
.
For more details, refer to the diarkisexec API reference.
Mesh Configuration
Specify the path to a JSON file in meshConfigPath
. For more details, refer to #mesh-she-ding.
UDP Server Configuration
Configurations are described in JSON format.
enableP2P
true
By setting to true, clients can obtain their public address for P2P.
address
"127.0.0.1"
Address to bind the UDP server
nic
"eth0"
Name of the interface to obtain the address. Used when the address is unspecified.
port
"7100"
Port to which the UDP server binds. It will automatically find available ports starting from the specified one.
connectionTTL
10
TTL for the connection. If this time is exceeded, the client will be disconnected from the server.
sendUDPInterval
0
Interval for sending UDP packets (milliseconds). If set to less than 10, send packets will not be buffered.
handleRUDPInterval
100 min: 10
Interval for RUDP packet transmission (milliseconds). A smaller value means the server will respond more sensitively (faster), but at the cost of increased CPU load.
retryInterval
1000
Retrial interval for RUDP packets (milliseconds)
maxRetry
10
Maximum retrials for RUDP packets. If this value is exceeded, the RUDP connection is considered timed out and discarded.
rcvWorkers
Number of CPU cores
Number of goroutines to receive UDP packets
enableEncryption
true
If set to false, packet encryption and decryption are disabled. The HTTP server must also be configured similarly.
⚠️ In cloud environments, use a private IP address for
address
, and utilize the environment variableDIARKIS_CLOUD_ENV
.
For more details, refer to the server API reference.
Last updated