LogoLogo
English
English
  • Diarkis Help Center
  • Overview of Diarkis
  • Getting Started
    • Diarkis Server Template
    • Diarkis Client SDK
    • Tutorials
      • 1. Launch Diarkis Server in Local Environment
      • 2. Perform Connectivity Check with Test Client
      • 3. Implement Custom Command
      • Connect to Server from Diarkis Client
    • Samples
  • Diarkis Modules
    • Room Module
      • Set Up Room Module on Server
      • Room Sample
        • room_broadcast
      • Utilizing Room Module from Client
      • Additional Features of Room
    • MatchMaker Module
      • Set Up MatchMaker Module on Server
    • Field Module
      • Set Up Field Module on Server
    • P2P Module
      • Set Up P2P Module on Server
      • P2P Sample
    • DM (Direct Message) Module
      • Set Up DM Module on Server
    • Notifier Module
      • Set Up Notifier Module on Server
    • Session Module
      • Set Up Session Module on Server
    • Group Module
      • Set Up Group Module on Server
  • Diarkis Server
    • Launch Diarkis Server in Cloud Environment
      • AWS
    • Launch Diarkis Server on Windows Environment
    • MARS Server
    • UDP Server
    • TCP Server
    • HTTP Server
    • Metrics API
    • Inter-server Communication - Mesh
  • Diarkis Client
    • Runtime Library
      • Diarkis RUDP
    • Diarkis Module
      • Initialization and Termination of Diarkis Module
      • Customization of Diarkis Module
      • Logging System of Diarkis Module
      • Migration
      • Threads of Diarkis
    • Samples
      • C++
        • room_broadcast
        • directmessage_simple
        • group_sample
        • matching_and_turn
        • matchmaker_ticket
        • p2p_rudp_sample
        • session_simple
      • Unreal Engine Plugin
        • FieldWalker
      • Unity Plugin
        • FieldWalker
          • HowToReplicatePosition.md
  • Diarkis Tools
    • Diarkis CLI
      • Procedures to Switch to Diarkis CLI v3
  • References
    • API Reference
    • Release Notes
      • v1.0
      • v1.0.1
      • v1.0.2
      • v1.0.3
      • v1.0.4
      • v1.0.5
      • v1.0.6
  • Support
    • License and Billing
Powered by GitBook
On this page
  • Overview
  • Setting up the UDP Server
  • Mesh Configuration
  • UDP Server Configuration

Was this helpful?

  1. Diarkis Server

UDP Server

PreviousMARS ServerNextTCP Server

Last updated 1 month ago

Was this helpful?

Overview

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.

Setting up the UDP Server

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 .

package main

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

var ver uint8 = 10
var cmd uint16 = 100

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()
}

func helloWorld(ver uint8, cmd uint16, payload []byte, userData *user.User, next func(error)) {
	userData.ServerRespond([]byte("Hello World"), ver, cmd, server.Ok, true)
	next(nil)
}

Mesh Configuration

Specify the path to a JSON file for meshConfigPath. For more details, refer to #mesh-she-ding.

UDP Server Configuration

Configure settings in JSON format.

{
  "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
}
Key
Default
Description

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.

In cloud environments, address should be set to a private IP address while using the environment variable DIARKIS_CLOUD_ENV.

For more details, refer to the .

⚠️
⚠️
diarkisexec API reference
server API reference