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 TCP Server
  • Mesh Configuration
  • TCP Server Configuration

Was this helpful?

  1. Diarkis Server

TCP Server

PreviousUDP ServerNextHTTP Server

Last updated 1 month ago

Was this helpful?

Overview

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.

Setting Up the TCP Server

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 .

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},
		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.SetupDiarkisTCPServer("/configs/tcp/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 the JSON file in meshConfigPath. For more details, refer to #mesh-she-ding.

TCP Server Configuration

The configuration is written in JSON.

{
  "connectionTTL": 10,
  "address": "127.0.0.1",
  "nic": "eth0",
  "port": "7200",
  "maxRcvSize": 8000,
  "noDelay": false,
  "enableEncryption": true
}
Key
Default
Description

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.

In a cloud environment, set the address to the private IP address and use the DIARKIS_CLOUD_ENV environment variable.

For more details, refer to the .

⚠️
⚠️
diarkisexec API Reference
server API Reference