TCP Server
Last updated
Was this helpful?
Last updated
Was this helpful?
The TCP server is one of the three real-time communication servers of Diarkis and can implement custom commands for an application.
Commands are formatted packets sent from clients and processed by the server. This is how the Diarkis server cluster interacts with clients.
To expose built-in commands to the client, you can set it up using the diarkisexec package.
You can expose built-in commands by specifying the module with diarkisexec.SetupDiarkis()
. By specifying ConfigPath
for each module, you can customize the settings.
You can expose custom commands using diarkisexec.SetServerCommandHandler()
.
You can set up a UDP server with diarkisexec.SetupDiarkisUDPServer()
. You can customize the server settings with the JSON file passed as arguments.
The above functions must be executed before calling
diarkisexec.StartDiarkis()
.
For more details, refer to the diarkisexec API Reference.
Specify the path to the JSON file in meshConfigPath. For more details, refer to #mesh-she-ding.
The configuration is written in JSON.
connectionTTL
10
The TTL for the connection. If this time is exceeded, the client is disconnected from the server.
address
"127.0.0.1"
The address to bind the UDP server to.
nic
"eth0"
The interface name to obtain the address from. Used when the address is not specified.
port
"7100"
The port for the UDP server to bind to. The UDP server will automatically find an available port starting from the specified port.
maxRcvSize
8000
The maximum TCP packet size (bytes) for each request packet.
noDelay
false
Set to true to disable Nagle’s algorithm (no buffering before writing).
enableEncryption
true
Set to false to disable encryption and decryption of packets. The HTTP server needs the same configuration.
For more details, refer to the server API Reference.
In a cloud environment, set the address to the private IP address and use the DIARKIS_CLOUD_ENV
environment variable.