This guide shows you how to run LightNet, an open-source relay you run on a dedicated server on Edgegap and can extend with your own game logic, so players of your host-client Unity game host a match and join it with a room code. The sample works with Mirror, Fish-Networking, PurrNet and Netcode for GameObjects, with one setting to pick the netcode.
Think of it as peer-to-peer, elevated. Out of the box, the relay forwards traffic and the host's game owns the match. Add game logic and it becomes a multi-room dedicated server with relay-like resource efficiency, on the same code and deployment. What changes from day one is where the traffic goes. Every player connects out to your relay, in a location you choose, so nobody opens a port, no player sees another player's IP address, and no shared relay network decides your route.
Once your relay is containerized, Edgegap deploys it from a simple API call, on Edge Cloud for tests or on Private Fleets for a relay that stays up. One relay serves many rooms at once.
This guide covers:
What you need before you start
Connecting your coding agent to Edgegap (optional)
Picking your netcode in the sample
Containerizing the relay and creating an app version
Deploying the relay and connecting players
Grouping players with room codes
Testing with two players
You can do it two ways, and mix them:
With a coding agent: Connected to the Edgegap MCP server and its agent skills, your agent can build and push the relay image, create the app version, deploy it, read its logs and stop it.
By hand: Every step below also works without an agent.
Here, we use Edgegap's LightNet relay sample: the relay, plus Mirror's Tanks game playing through it on all four netcodes.
Which setup fits your game?
An extensible relay is one of six ways to put players in the same match. They differ in who owns the match and where it runs:
Setup | Who owns the match | Best for |
|---|---|---|
A player's device | Local or LAN-style play | |
Shared relay service (Steam, Epic Online Services, Unity Relay) | The host player | A quick fix for connections that fail |
Extensible relay (this guide), on a dedicated server | The host player | Co-op and private rooms among players who trust each other, with your own relay and route; add game logic to grow it into a multi-room game server |
The server | Latency-tolerant games such as RTS, card and turn-based games, with many matches in one central process | |
The server | Matches where fairness matters, each on a fractional vCPU server deployed nearest to its players | |
The server | Full simulations, large matches and anti-cheat |
What an extensible relay gives you:
Players' IP addresses stay hidden: Everyone connects out to the relay, so players never connect to each other directly. That closes the door on attacks on a player's connection, such as flooding the host, that peer-to-peer leaves open.
No port forwarding, no NAT issues: Including on mobile networks, where direct peer-to-peer connections often fail.
Your route, your locations: Deploy the relay where your players are. On free relay services, studios have reported "absolutely no control over how those players are routed" (Live Service Game Summit talk, September 2024).
No shared network: A routing change or outage on another relay network doesn't reach your game.
No rewrite: Your host-client netcode stays as it is, with no relay vendor SDK in your game.
Extend it: You own the relay code, so you can add your own logic: room passwords or player checks, rate limits, kick and ban, room data, telemetry, hooks to your lobby. Shared relay services like Steam's and Epic's don't let you add code.
Grow it into a game server: Add game logic and it becomes a multi-room dedicated server with relay-like resource efficiency, on the same code and deployment.
What it can't do:
Stop cheating out of the box: Whoever holds the match state can change it, and as shipped, the host's game holds it. A cheater ruins the match for everyone, casual or ranked. Server authority stops that: add game logic so the relay holds the match, which means rebuilding your game's rules on the server since the relay only sees raw netcode traffic, or move to a small dedicated server per match. A multi-room server runs in one location, so run one per region: players far from it get worse latency and fairness than players close to it.
Keep the match going when the host leaves: The relay closes the room and disconnects the other players.
Match players or scale on its own: The sample has no matchmaking and no scaling: players share room codes, and you choose where to deploy relays.
Encrypt traffic or check who joins, as shipped: The sample's transports are plain TCP and UDP, and anyone with the relay address and a valid room code can join until you add your own player checks.
Serve browser games: For web games, see Browser Games, Colyseus or Manus AI.
Where it fits:
Main fits: co-op games, mobile games including hybrid-casual, realtime PvP among friends or in private rooms, RTS and card games (TCGs), all without server logic. Other game types may work too.
For co-op specifically, see why co-op casual games need a dedicated game server too.
For a side-by-side of every network model, see authoritative servers, relays and peer-to-peer.
1. Before you start
- A free Edgegap account. Verify your email. No credit card is needed to test.
- Unity 6000.0.54f1 (Unity 6), the version the sample uses. PurrNet needs Unity 2022.3 or newer.
- Docker to build the relay image. Other containerization tools aren't covered here. The .NET 8 SDK is only needed to build the relay outside Docker.
- For the agent path: an Edgegap API token, from Dashboard → User Settings → Tokens. It is organization-wide, so treat it like a password: never put it in your project, your game client or a chat.
Git: Unity needs a Git client (2.14.0 or newer) on your PATH to install packages from a Git URL, such as PurrNet in this sample. macOS usually has one already (Xcode Command Line Tools); on Windows, install Git.
Clone the sample: git clone https://github.com/edgegap/server-sample-lightnet-relay.git
2. Connect your coding agent to Edgegap
Skip this step if you're doing everything by hand.
The Edgegap MCP server lets your agent work on your account: push images, create app versions, deploy, read logs and stop deployments. The skills hold the tested workflow.
Claude Code: install the Edgegap plugin. It adds both the MCP server and the skills, and asks for your API token during install (stored in your system's credential store):
/plugin marketplace add edgegap/llm-agent-skills, then /plugin install edgegap@edgegap. Restart the session.
Only want the MCP server, without the plugin? Run this in your own terminal instead: claude mcp add --transport http edgegap https://mcp.edgegap.dev/mcp -H "Authorization: token YOUR_EDGEGAP_API_TOKEN" --scope user. Don't do both, or you'll have two edgegap servers.
Cursor, VS Code and other clients that send headers: add https://mcp.edgegap.dev/mcp with the header Authorization: token YOUR_EDGEGAP_API_TOKEN, and install the skills with npx skills add edgegap/llm-agent-skills --skill "*".
Claude Desktop: custom connectors can't send the header, so use the local server instead (Node 18+): { "mcpServers": { "edgegap": { "command": "npx", "args": ["-y", "@edgegap/mcp"] } } }. It asks for the token on first use.
Check it works:
List my Edgegap apps.
An empty list is fine. Your agent may also point out that a dedicated server would give your game server authority: that's expected, since a relay leaves the host in charge of the match.
3. Pick your netcode in the sample
Open the tanks/ folder in Unity Hub. The netcode is one field, netcode, in tanks/Assets/Tanks/Resources/TanksSettings.asset: Mirror, FishNet, PurrNet or NGO. The same asset holds the relay address and port. Other ways to switch:
- In the editor: Tanks > Netcode > Mirror / FishNet / PurrNet / NGO sets the asset and opens that netcode's scene.
- In the game: the netcode buttons at the top of the HUD, before hosting or joining.
- From the command line:
-netcode FishNet.
Host and players must use the same netcode. One build contains all four.
| Netcode | Version in the sample | Relay transport |
|---|---|---|
| Mirror | 66.0.9 | MirrorRelayTransport |
| Fish-Networking | 4.7.4 | FishNetRelayTransport |
| PurrNet | 1.24.1 | PurrNetRelayTransport |
| Netcode for GameObjects | 1.13.0 | NgoRelayTransport |
Each transport wraps RelayPeer, the netcode-agnostic relay client in the sample's LightNet package. Reliable messages go over TCP and unreliable ones over UDP, up to 16 KB reliable and 1,177 bytes unreliable per message.
Your own game? Copy the LightNet/ package and the transport for your netcode into your project, and set it as your Network Manager's transport. Your game keeps hosting the match as it does today.
"In my Unity project using {netcode}, add the LightNet package from Edgegap's server-sample-lightnet-relay repository and its {netcode} relay transport. Set it as the Network Manager's transport, read the relay address and port from a settings asset, and add Host and Join room buttons: Host shows the 6-letter room code, Join takes one. Don't change my game logic."
4. Containerize the relay and create an app version
The relay is a .NET 8 console app with its own Dockerfile. Build it from the repository root, for Edgegap's platform, even on Apple Silicon:
docker build --platform linux/amd64 -f relay-server/Dockerfile -t registry.edgegap.com/<project>/lightnet-relay:<tag> .
Test it on your machine first: docker run --rm -p 7777:7777/tcp -p 7777:7777/udp registry.edgegap.com/<project>/lightnet-relay:<tag>. The log should read "LightNet relay listening on TCP 7777, UDP 7777".
Push to the Edgegap Container Registry: run docker login registry.edgegap.com yourself, with the username and token from the Container Registry page, then docker push. Use a new tag for every build, never latest.
Then create the application and its version in the dashboard:
- Your image and tag, with registry credentials (without them, deployments fail with "Unable to pull image from registry").
- One port: 7777, protocol
TCP/UDP, namedgameport. Two separate 7777 TCP and 7777 UDP entries are rejected as duplicates. - Start small on resources: the relay runs no game logic. To size it on real traffic, move off the free tier by adding a credit card (Pay as You Go): it unlocks detailed deployment metrics, so you can see the relay's CPU, memory and network use in a live environment and adjust.
- Optional environment variables:
RELAY_MAX_PEERS(players per relay, default 256) andRELAY_IDLE_EXIT_SECONDS(the relay exits after that many seconds with no room; 0 means never).
With your agent:
"Load the edgegap-containerize skill. Build the LightNet relay from relay-server/Dockerfile at the repository root for linux/amd64, push it to the Edgegap registry with a new tag, then create an Edgegap app and app version for it: one port 7777 with protocol TCP/UDP named gameport, registry credentials set, small resources, restart policy never."
5. Deploy the relay and connect players
Deploy your version from the dashboard (Deploy, pick a location close to your players), or ask your agent:
"Deploy my LightNet relay version near me, wait until it's ready, show me the logs, and give me the host URL and external port."
When the deployment is Ready, players connect to its Host URL (<id>.pr.edgegap.net) and External Port. Edgegap maps TCP and UDP to the same external port, so players pass it once:
- In the sample: set the relay address and port in
TanksSettings.asset, or use-relay <host>.pr.edgegap.net -relayPort <external port>on the command line. - In the relay's log, a peer that connects and leaves right after start is Edgegap's readiness check, not a player.
Keeping relays up:
- Free tier: deployments stop after 60 minutes, which is enough to test.
- Edge Cloud: deployments are meant to be recycled within 24 hours, and you're warned when one runs longer. Edge Cloud also bills egress, and a relay forwards every byte of every match. As such, it may be ideal for on-demand levels of usage, or for development, playtests and pre-production, but at scale, we recommend studios use Private Fleets for greater cost-effectiveness.
- Private Fleets: once your game is live and relays run around the clock, Private Fleets are usually the better fit: reserved hosts in 58 locations worldwide, with 6 TB of egress included per host, enough for almost every game, and persistence settings to decide how long each relay runs.
- Recycling: on any setup, recycling relays regularly is best practice, since a fresh game server is a healthy one (see Edgegap's deployment lifecycle). When, how and how often depends on your game, and the persistence guide covers planning restarts without hurting players. A simple way per region: start a new relay, give its address to players who host new rooms, and stop the old relay once its last room ends.
- Test deployments: make sure to stop them from the dashboard or your agent when you're done, since a deployment bills while it runs.
6. Group players with room codes
The sample groups players with room codes, not a matchmaker:
A player presses Host. The relay creates a room and returns a 6-letter code, shown in the HUD.
The host shares the code: in a party screen, a friends list, a chat or a Discord message.
Other players type the code and press Join room.
Codes skip I and O, so they're easy to read out loud. The room lasts as long as the host stays: when the host leaves, the relay closes the room and disconnects the others. The host can also kick a player.
To bring this into your game, show the code in your own UI and pass it through whatever already connects your players, such as Steam or Epic Online Services friend invites.
When you need matchmaking: Room codes work among friends. For public matches with strangers, casual or ranked, a cheater ruins everyone's fun, so give the match to a server: extend the relay with your game logic, or start with Mirror Networking, Fish-Networking, PurrNet or Netcode for GameObjects, which cover dedicated servers and Edgegap's Matchmaking end to end.
7. Test with two players
- Build the Windows client: Tanks > Build Windows client.
- Start two copies. In the first, press Host and note the room code. In the second, type the code and press Join room.
- Both tanks appear in both games. Drive and fire: the host sees the other tank move and its shots land.
Automated test: With the relay running, ./e2e.sh <host>.pr.edgegap.net <external port> starts a host and a client on each netcode and checks that both games see two tanks, that reliable and unreliable data went through the relay, and that a projectile spawned. Name netcodes to test only some: ./e2e.sh <host>.pr.edgegap.net <external port> FishNet NGO. It runs the Windows build from a Bash shell, such as Git Bash. The sample passed this test on Edgegap on all four netcodes on 29 October 2026.
Stop the deployment when you're done.
Ready for server authority? No host advantage, no cheating host, and the match survives anyone leaving: see the guides for Mirror Networking, Fish-Networking, PurrNet and Netcode for GameObjects. Or extend the LightNet relay with your own game logic. Or extend the LightNet relay with your own game logic. Prefer a managed relay instead of running your own? See Unity Relays.
Stuck? Ask our team and other studios on the Edgegap Discord.
常见问题
Common questions about running an extensible LightNet relay on a dedicated server for a host-client Unity game.
What is LightNet?
LightNet is a lightweight, open-source C# networking library (Apache 2.0) with server and client modes, reliable and unreliable channels, and no built-in game logic. In this sample, it runs as a relay: a .NET console app in a container that forwards traffic between a host player and the others in each room.
Is an extensible relay a dedicated game server?
Not out of the box. It runs on a dedicated server, but as shipped it runs no game logic: the host player's game owns the match, as in peer-to-peer. What it adds over peer-to-peer and shared relay services is your own relay: hidden IP addresses, no port forwarding, a location you choose, and code you can extend. Add game logic to the relay and it becomes a multi-room dedicated server with relay-like resource efficiency.
Does a relay stop cheating?
Not on its own. Whoever holds the match state can change it, and with a relay that's the host's game. A cheater ruins a match for everyone, whether it's casual or ranked. The LightNet relay does stop attacks on players' connections, since nobody sees another player's IP address. Stopping cheating takes server authority: add game logic so the relay holds the match, or use a small dedicated server per match.
Which netcodes does the sample support?
Mirror, Fish-Networking, PurrNet and Netcode for GameObjects, in one Unity 6 build, with one setting to switch. The relay doesn't know which netcode is used: it forwards bytes. Another netcode needs its own transport around the sample's RelayPeer client.
How is this different from Edgegap's Unity Relays?
Unity Relays are Edgegap's managed Distributed Relays: you create a session per match from an API call, and Edgegap picks the relay. With LightNet, you run the relay yourself as an Edgegap deployment, with your own code and room codes, you choose where it runs, and you can extend it with your own logic.
Can I use the LightNet relay for browser games?
Not with the sample as it is: its transports are TCP and UDP, which browsers can't open. For web games, see Browser Games, Colyseus or Manus AI.

客户
了解更多已接入 Edgegap 的客户案例
提供 31 个从其他平台迁移至 Edgegap 的工作室案例研究。

《以太之战 2》完美的全球发布
Aether Studios
了解Aether Studios是如何快速添加Edgegap并向他们的社区交付完美的启动和后启动服务的。
Case Study

克服因虚拟现实在竞技Multiplay中使用WiFi而引入的延迟
Halfbrick Studios
Discover how Halfbrick successfully launched & maintains a multiplayer-focused Early Access on META Quest's VR platform.
Case Study

MENA的社交应用添加了在线游戏
WOLF
了解这款在中东和北非地区广受欢迎的社交应用如何轻松地将 matchmaking 和多人游戏编排添加到 WOLF Qanawat。
Case Study

混合编排让开球策略随时应对任何流量做好准备
Birch Games
混合编排如何帮助 Birch Games 应对流量——将免流出费用的 Fleets 与无区域限制云相结合。
Case Study

7天血月
The Fun Pimps & iLLOGIKA
了解 Illogika 如何大幅降低服务器成本,并确保提供《七日杀 (7 Days to Die)》玩家所期望的在线体验。
Case Study

真实的在线战争需要终极的协调
Highwire Games
了解Highwire对性能的需求如何需要只有Edgegap才能提供的编排。
Case Study

22,000 条评价、4.8 颗星以及自动扩展的基础架构
Sinn Studios
一个由 Slack 提供支持的简单集成,如何让 Sinn Studio 的热门 VR 游戏快速上线并保持稳定运行。
Case Study

动态服务器编排
Under NDA - AAA Studio
了解世界上最大的AAA工作室之一如何通过边缘计算改善其对等多人游戏体验。
Case Study

对于 AAA 格斗游戏的近零延迟
AAA Studio - Under NDA
一个未宣布的项目如何实现了最低延迟,并改善了其1v1游戏中的公平性。
Case Study

Play Gods with Multiplayer Physics
Squido Studio
Learn how Squido uses Edgegap's highligh optimized game servers to deliver mind-bending & chaotic VR gameplay.
Case Study

全面托管的解决方案为独立游戏节省时间 多人VR恐怖游戏
Dirty Pearl Studios
了解Dirty Pearl Studios如何通过Edgegap的轻松集成和自动编排,以及其Nakama集成,节省了开发时间。
Case Study

即时全球服务器部署以促进协作式XR医学教育
AlensiaXR
AlensiaXR如何利用Edgegap为全球医学生提供低延迟、始终可用的共享解剖课程。
Case Study

守光人:具有专用服务器的 VR 社交合作游戏
Spectral Games
Spectral Games 如何在无需任何服务器经验的情况下,利用 Edgegap Matchmaking 和 Server Browser 为其 VR 社交大厅启动专用服务器。
Case Study

全球范围内快速可靠的部署,适用于PvPvE挑战者Gravebound
Crater Studios
Edgegap 的调度和配对如何帮助 Crater Studios 使他们能够将重心从基础设施转移到游戏玩法上。
Case Study

快速扩展网络元宇宙
Hiber
了解Hiber如何通过Edgegap消除服务器容量规划中的猜测。
Case Study

高硬件要求和自定义游戏服务器池
Alderon Games
了解Alderon Games如何瞬间利用全球多个供应商的自定义游戏服务器池来支持其热门MMO。
Case Study

独立开发者的简单集成
WhaleFood Games
阅读关于WhaleFood Games如何使用Edgegap解决其网络代码问题的文章。
Case Study

推动东南亚首款电子竞技游戏的尖端技术。
Anantarupa Studios
了解Edgegap如何通过一个无缝解决方案简化复杂基础设施和尖端技术,从而改变东南亚的游戏格局。
Case Study

一次打击。全球抵达。
Triple Hill Interactive
Triple Hill Interactive如何利用Edgegap的编排来提供低延迟,并提高在每毫秒都至关重要的游戏类型中的公平性。
Case Study

快节奏团队大逃杀...带着枪的动物毛绒玩具!
SANDYFLOOR
了解一家韩国独立工作室是如何将其多人游戏发布到全球的。
Case Study

移动端赛马游戏凭借即时、高效能的服务器走向全球
Mirai Labs
看 Mirai Labs 如何通过即时服务器部署和细分 vCPU 来运行 Pegaxy Blaze 的全球多人竞速游戏,从而将单个玩家的成本保持在极低水平。
Case Study

服务器管理与分发
Matrioshka Games
阅读关于Matrioshka Games如何在资源有限的情况下发布早期访问的战斗 Royale。
Case Study

听我的信号,释放地狱!
TyGames
探索独立工作室TyGames如何让玩家沉浸在第三人称角斗士战斗的多人游戏中。
Case Study

瞬时全球编排
Soliton Interactive
探索Soliton Interactive如何做到了不可能……首次推出可多人玩的版本!
Case Study

竞技游戏具有服务器端物理引擎,确保理想的低于50毫秒的延迟
NS7
了解为什么仅有Edgegap能够使独立工作室通过服务器端物理和权限实现其AAA质量的免费游戏体育玩法愿景。
Case Study

iGaming的区域部署
X1 Contra 1
X1 Contra 1 通过经济高效的托管和区域部署,为其巴西玩家提供实时 PvP 休闲游戏,确保数据和法律合规。
Case Study

仅在玩家游玩时付费:经济实惠的多人游戏基础设施
Meltdown Interactive
Edgegap 如何帮助独立开发商 Meltdown Interactive Media 在无需复杂方案的情况下,以高性价比解决扩缩容和匹配问题,从而让他们能够专注于游戏开发。
Case Study

同一个 Edgegap 平台,三种截然不同的网络配置
Warped Games
了解 Warped Games 如何在同一个 Edgegap 部署 API 和同一个容器管线上运行社交中心、实时合作以及回合制合作。
Case Study

台球大师巡回赛Max
RETA Games
Case Study

韩国的Web3 POP提取射击游戏走向全球,即刻启程
NDUS Entertainment
XOCIETY 如何轻松地添加 Edgegap 编排并集成自定义 matchmaking,与 Edgegap Ping Beacons 一起优化延迟。
Case Study

Multiplayer in Every Dimension
Arcadia.tv
Discover how Arcadia.tv uses Edgegap's edge network to deliver an innovative, team and location-based athletic VR sport.
Case Study

F2P 移动格斗游戏利用即时(Just-In-Time)服务器降低基础设施成本
Game Changers Worldwide
Game Changer Worldwide 如何在全球移动端托管 Rumble Rush 的实时 3v3 PvP 游戏。
Case Study
他们选择 Edgegap 的关键原因
了解 Edgegap 自动化游戏服务器编排如何带来无缝的多人游戏体验。









