This page explains how Room Servers work to facilitate communication between clients and dedicated servers.
Overview
Room Servers provide a system for tracking, managing, and sharing data between clients and dedicated servers in server-hosted sessions. They integrate with both Unity's Multiplay service for server allocation and Unity Relay for WebSocket connections.
Distributing Server Builds
To build and distribute dedicated server code, we provide an editor tool which can be found at (Kanda SDK > Distribution > To Unity Multiplay Hosting...).
This tool helps automate the build process, and upon entering Unity Cloud Service Account credentials with the Game Server Hosting API Manager for your project, you can upload your build to a new or existing Multiplay Build Configuration.
Server Allocation Flow
When a client requests a server-hosted session, the following process occurs:
- The client calls the Kanda Cloud Room Server Join endpoint with session/room information
- Kanda Cloud initiates server allocation
- The Join endpoint returns the current status of the server:
Queued - Server allocation has been requested
Starting - Server is booting up
Running - Server is ready for connections
Error - Server failed to start
- The client polls the Join endpoint until server status is
Running
- Once running, the Join endpoint provides connection details:
- For UDP connections: Server IP and port
- For WebSocket connections: Unity Relay join code
Server Authentication
Room Servers need to communicate with Kanda Cloud to share information with clients. This is handled through a secure authentication process:
- When Kanda Cloud allocates a server via Unity Multiplay, it includes temporary credentials in the allocation payload
- The server retrieves these credentials from the allocation payload on startup
- These credentials allow the server to interact with designated Kanda Cloud endpoints
- The credentials are scoped specifically to that server instance and expire after the server shuts down
WebSocket Connections
When WebSocket connections are enabled in the SDK settings, additional steps occur during server startup:
- Server boots and retrieves credentials from allocation payload
- Server creates and connects to a Unity Relay allocation to enable WebSocket connections
- Server obtains a join code for the Relay allocation
- Server shares this join code with clients via Kanda Cloud Room Server Update endpoint
- Clients receive the join code through the Room Server Join endpoint
- Clients connect to the server through Unity Relay using WebSockets
Server Allocation Timing
Room Server allocation is an asynchronous process that can take time:
- Initial allocation request may queue the server
- Server must be started on Unity Multiplay infrastructure
- Server must complete boot process and initialize services
- For WebSocket connections, Relay setup adds additional steps
UI can handle this by polling the Join endpoint and tracking server status. This allows clients to:
- Queue a server allocation
- Monitor allocation progress
- Connect once server is ready
- Timeout if allocation takes too long
Example Status Flow
Client → Join Request → "Queued"
Client → Poll Join → "Starting"
Client → Poll Join → "Starting"
Client → Poll Join → "Running" → Connect