UDP Server
Last updated
Was this helpful?
Last updated
Was this helpful?
The UDP server is one of the three real-time communication servers of Diarkis.
It allows for the exposure of built-in commands from pre-prepared modules to clients, or for the implementation and exposure of custom commands.
Commands are formatted packets sent from the client and processed by the server. By using commands, the Diarkis server cluster interacts with clients.
To expose built-in commands to clients, you can set them up using the diarkisexec package.
You can expose built-in commands by specifying modules with diarkisexec.SetupDiarkis()
. By specifying the ConfigPath
for each module, you can customize the settings.
Custom commands can be exposed with diarkisexec.SetServerCommandHandler()
.
The setup of the UDP server can be done with diarkisexec.SetupDiarkisUDPServer()
. The server settings can be customized using a JSON file as an argument.
These functions need to be executed before calling
diarkisexec.StartDiarkis()
.
For more details, refer to the diarkisexec API reference.
Specify the path to a JSON file for meshConfigPath
. For more details, refer to #mesh-she-ding.
Configure settings in JSON format.
enableP2P
true
When set to true, clients can obtain their public address for P2P use.
address
"127.0.0.1"
Address for the UDP server to bind to
nic
"eth0"
Name of the interface to obtain the address. Used when the address is not specified.
port
"7100"
Port for the UDP server to bind. The UDP server automatically finds an available port starting from the specified port.
connectionTTL
10
TTL for the connection. If this time is exceeded, the client is disconnected from the server.
sendUDPInterval
0
Interval for sending UDP packets (ms). If set to less than 10, sent packets are not buffered.
handleRUDPInterval
100 min: 10
Interval for sending and receiving RUDP packets (ms). The smaller the value, the more responsive (faster) the server will be, but at the cost of increased CPU load.
retryInterval
1000
Retry interval for RUDP packets (ms)
maxRetry
10
Maximum retry count 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 for receiving UDP packets
enableEncryption
true
Setting to false disables packet encryption and decryption. The HTTP server must be configured similarly.
For more details, refer to the server API reference.
In cloud environments, address should be set to a private IP address while using the environment variable DIARKIS_CLOUD_ENV
.