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 the ConfigPath 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.

For more details, refer to the diarkisexec API reference.

package main

var ver uint8  = 10
var cmd uint16 = 100

import (
	"github.com/Diarkis/diarkis/diarkisexec"
)

func main() {
	logConfigPath := "/configs/shared/log.json"
	meshConfigPath := "/configs/shared/mesh.json"

	diarkisexec.SetupDiarkis(logConfigPath, meshConfigPath, &diarkisexec.Modules{
		Room:       &diarkisexec.Options{ExposeCommands: true},
		P2P:        &diarkisexec.Options{ExposeCommands: true},
		Group:      &diarkisexec.Options{ConfigPath: "/configs/shared/group.json", ExposeCommands: true},
		Dive:       &diarkisexec.Options{ConfigPath: "/configs/shared/dive.json", ExposeCommands: true},
		Field:      &diarkisexec.Options{ConfigPath: "/configs/shared/field.json", ExposeCommands: true},
		DM:         &diarkisexec.Options{ConfigPath: "/configs/shared/dm.json", ExposeCommands: true},
		MatchMaker: &diarkisexec.Options{ConfigPath: "/configs/shared/matching.json", ExposeCommands: true},
		Session:    &diarkisexec.Options{ConfigPath: "/configs/shared/session.json", ExposeCommands: true},
	})

	diarkisexec.SetupDiarkisUDPServer("/configs/udp/main.json")
	
	diarkisexec.SetServerCommandHandler(ver, cmd, helloWorld)

	diarkisexec.StartDiarkis()
}

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.

{
  "enableP2P": true,
  "address": "127.0.0.1",
  "nic": "eth0",
  "port": "7000",
  "connectionTTL": 10,
  "sendUDPInterval": 0,
  "handleRUDPInterval": 100,
  "rcvWorkers": 1,
  "retryInterval": 1000,
  "maxRetry": 10,
  "enableEncryption": true
}

For more details, refer to the server API reference.

最終更新