Discover how Edgegap works

Discover how Edgegap works

/

LightNet Relay

/

LightNet Relay

Deploy to Edgegap

Published

Published

Published

Last reviewed for accuracy

Last reviewed for accuracy

Last reviewed for accuracy

LightNet Relay for Unity: How to run an extensible relay on a dedicated server, with room codes and optional game logic

LightNet Relay for Unity: How to run an extensible relay on a dedicated server, with room codes and optional game logic

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, or get matched through Edgegap’s optional matchmaker. 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:

  1. What you need before you start

  2. Connecting your coding agent to Edgegap (optional)

  3. Picking your netcode in the sample

  4. Containerizing the relay and creating an app version

  5. Deploying the relay and connecting players

  6. Grouping players with room codes

  7. Matching players with the Edgegap matchmaker, including joining running matches (optional)

  8. 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.

No credit card required. Free tier includes the resources to deploy a real game server.

No credit card required. Free tier includes the resources to deploy a real game server.

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

Peer-to-peer

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, or quick matches with Edgegap’s matchmaker, with your own relay and route; add game logic to grow it into a multi-room game server

Multi-room game server

The server

Latency-tolerant games such as RTS, card and turn-based games, with many matches in one central process

Small dedicated server

The server

Matches where fairness matters, each on a fractional vCPU server deployed nearest to its players

Full dedicated server

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.

  • Fill running relays first: With the optional matchmaker, players who press Find Match join a nearby relay first, in a room with a free seat or a new room on it, before a new relay is deployed. No room code needed.

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.

  • Keep the match fair with strangers: The sample has optional matchmaking. The Edgegap matchmaker groups players near each other and places their match on a relay near them, but the host’s game still owns the match. For public matches with strangers, casual or ranked, give the match to a server.

  • Encrypt end to end: The default transports are plain TCP and UDP. An optional wss:// connection, with Edgegap’s TLS Upgrade, encrypts traffic between each player and Edgegap, but the relay and the host’s game still see it. With room codes, anyone with the relay address and a valid code can join until you add your own player checks. With the matchmaker, the relay only gives the room code to the matched players’ tickets.

  • Serve browser games: The WebSocket option has no browser (WebGL) bridge yet. For web games, see Browser Games, Colyseus or Manus AI.

Where it fits:

Step-by-Step Guide

Detailed Integration Steps

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 and the Edgegap Unity SDK (used by the optional matchmaker) 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, and the optional matchmaker settings (off by default). 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. Players can also connect over one WebSocket instead: give the game a ws:// or wss:// relay address. Over WebSocket, unreliable messages travel reliably and in order, which suits co-op and turn-based games better than fast shooters. Players on TCP + UDP and on WebSocket can share a room.

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 -p 7778:7778/tcp 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, named relay. Two separate 7777 TCP and 7777 UDP entries are rejected as duplicates. For the optional encrypted WebSocket, add a second port: 7778, protocol WS, TLS Upgrade on, named relay-ws. Players then connect to wss://<host>.pr.edgegap.net:<its external port>.

  • 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) and RELAY_IDLE_EXIT_SECONDS (the relay exits after that many seconds with no room; default 600, so an idle relay stops itself after 10 minutes; 0 means never). RELAY_WS_PORT sets the WebSocket port (default 7778, 0 turns it off). A relay started by the matchmaker stops itself when its last room ends. For the matchmaker, also add MATCHMAKER_URL and MATCHMAKER_TOKEN, and optionally RELAY_MATCH_MAX_PLAYERS (players per room, default 4), RELAY_MAX_ROOMS (rooms per relay, default 4) and RELAY_SOLO_ROOM_SECONDS (default 120): see step 6.

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 relay, 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.

  • Matchmaker relays: with the matchmaker, a relay starts near its first players on Edge Cloud and takes up to 4 rooms. It stops itself when its last room ends, so it bills only while players play. On the free tier, only one deployment runs at a time (one relay), and the matchmaker shuts down 3 hours after each start.

  • 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: room codes or matchmaking

The sample groups players two ways: room codes, or, optionally, Edgegap’s matchmaker.

With room codes:

  1. A player presses Host. The relay creates a room and returns a 6-letter code, shown in the HUD.

  2. The host shares the code: in a party screen, a friends list, a chat or a Discord message.

  3. 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.

With the Edgegap matchmaker (optional, off by default):

  1. In the dashboard, open Matchmaker → Create Matchmaker. Upload matchmaker-config.json from the repository, with application.name and version set to your relay’s app version, then click Create and Start. The file uses matchmaker 3.3.3, profile casual and a 30 s ticket expiration. For its first 10 seconds, a ticket can only join a running relay; then 2 to 4 waiting players get a new one. A latency rule keeps players together only when each has at most 150 ms to an Edgegap beacon and their pings differ by at most 100 ms.

  2. On your relay’s app version, add the environment variables MATCHMAKER_URL and MATCHMAKER_TOKEN: the matchmaker’s API URL and Auth Token. Without them, the relay logs “backfill: off” and its rooms never take later players.

  3. In TanksSettings.asset, turn on Use Matchmaker and paste the same API URL and Auth Token. The token is safe to ship in a game client. The game sends its pings to Edgegap’s beacons with each ticket (matchmakerLatencyBeacons, on by default). Command-line version: -matchmaker <url> -matchmakerToken <token> -findMatch. To connect over wss://, also turn on matchmakerUseWebSocket (-matchmakerWebSocket).

  4. Players press Find Match. If a nearby relay has room, the player joins it: a room with a free seat first, otherwise a new room on that relay, which the player hosts. If none has room, after about 10 seconds the matchmaker deploys a new relay for 2 to 4 waiting players near each other. The first matched player to reach a room hosts it, and the others join automatically, with no code to type.

  5. Each relay holds up to 4 rooms of up to 4 players (RELAY_MAX_ROOMS, RELAY_MATCH_MAX_PLAYERS) and keeps at most 5 backfills open: requests at the matchmaker that carry the relay’s address and its players’ pings. It offers a new room only once its rooms are full, so two players searching at the same time end up together.

  6. A host left alone for 2 minutes (RELAY_SOLO_ROOM_SECONDS) is told, and the game searches again by itself. When a host leaves, that room closes. Once its last room ends, the relay closes its backfills and stops its own deployment, so it stops billing.

A relay deployed without the matchmaker keeps working with room codes. Players can join a room in progress, so your game must accept players mid-match, as Tanks does. The sample queues players one at a time; for parties, add a backfill_group_size rule so a party never takes more seats than a room has free. Browsers can’t ping beacons, so a WebGL build needs a profile without the latency rule.

“Load the edgegap-matchmaking skill. Build a matchmaker config (version 3.3.3) for my LightNet relay app version: profile casual, 1 team, min and max team size 9999 at first so tickets only join running relays through backfill, then an expansion at 10 s to 2 to 4 players, a beacons latency rule (max latency 150 ms, difference 100 ms) and a 30 s ticket expiration. Tell me how to create it in the dashboard, add MATCHMAKER_URL and MATCHMAKER_TOKEN to my app version, and put the URL and token in TanksSettings.asset with Use Matchmaker on.”

Matchmaking with strangers: The matchmaker puts strangers in the same room, but the host’s game still owns it, so a cheating host can ruin it, and the room ends for everyone in it, later joiners included, when the host leaves. For public casual or ranked matches, 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

  1. Build the Windows client: Tanks > Build Windows client.

  2. Start two copies. In the first, press Host and note the room code. In the second, type the code and press Join room.

  3. 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.

With the matchmaker: Start two copies and press Find Match in both. One hosts and the other joins. Automated: ./e2e-matchmaker.sh <matchmaker url> <token> runs games through the matchmaker on each netcode (add FishNet NGO to test only some). Prefix it with BACKFILL=1 to add a later third player, MULTIROOM=1 to fill a room and then host and join a second room on the same relay, or MM_WEBSOCKET=1 to run over wss://. With real pings from Montreal, the sample passed all of them on Edgegap on all four netcodes on 2 November 2026: the second room ended while the first kept playing, each relay stopped itself after its last room, and a player with far-away pings was never put in the running room. Over WebSocket with room codes: ./e2e.sh wss://<host>.pr.edgegap.net:<port> 0.

Stop the deployment when you're done.

Next Steps

Next Steps

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. Prefer a managed relay instead of running your own? See Unity Relays.

Stuck? Ask our team and other studios on the Edgegap Discord.

Frequently Asked Questions

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 players find a match without room codes?

Yes. Turn on the sample’s optional Edgegap matchmaking. Players press Find Match: if a nearby relay has room, they join it, in a running room or a new one; otherwise the matchmaker groups players near each other and starts a relay for them. The relay picks one player to host each room and lets only matched players in. The host’s game still owns the match, as with room codes.

Clients

Learn more from clients who integrated Edgegap

31 case studies are available from studios that moved to Edgegap from another platform.

Key reasons why they chose Edgegap

Discover the impact of Edgegap's automated game server orchestration for a flawless multiplayer experience.

Cost

Pricing

Pricing

Optimize costs and performance with hybrid orchestration

Optimize costs and performance with hybrid orchestration

Optimize costs and performance with hybrid orchestration

Edge Cloud

On-Demand

$0.00115

/ vCPU

/ MINUTE

Billed by the Minute, Only on Usage

Pay only when players play. 0 active servers = $0

Deploy game servers worldwide, per instance, to all 615+ edge cloud locations. Zero commitment.

Simply add a credit card.

Edge Cloud

On-Demand

$0.00115

/ vCPU

/ MINUTE

Billed by the Minute, Only on Usage

Pay only when players play. 0 active servers = $0

Deploy game servers worldwide, per instance, to all 615+ edge cloud locations. Zero commitment.

Simply add a credit card.

Private Fleet (Bare Metal)

Reserved Capacity

$0.0261

/ vCPU

/ HOUR

Billed Monthly, Always On

$280 per host/month (12 mo rate), or $350 monthly

Optimize the cost effectiveness of your game server with egress-free hosting of Private Fleets.

Persistent, available 24/7, exclusive to your studio.

Private Fleet (Bare Metal)

Reserved Capacity

$0.0261

/ vCPU

/ HOUR

Billed Monthly, Always On

$280 per host/month (12 mo rate), or $350 monthly

Optimize the cost effectiveness of your game server with egress-free hosting of Private Fleets.

Persistent, available 24/7, exclusive to your studio.

Your bill varies per rate and usage; which can vary per game type, player count, & more.

Your bill varies per rate and usage; which can vary per game type, player count, & more.

Model your usage with our estimate calculator ->

Model your usage with our estimate calculator ->

Edgegap's features & price: detailed comparison between Edge Cloud & Private Fleets

Edgegap's features & price: detailed comparison between Edge Cloud & Private Fleets

COMPARE

Free Trial

Edge Cloud

Private Fleets

FEATURES

Analytics & Monitoring

Billing Alarms

Click to Expand

28 more rows

Unlocks

Capabilities are unlocked when a credit card is added to the account.

COMPARE

Free Trial

Edge Cloud

Private Fleets

FEATURES

Analytics & Monitoring

Billing Alarms

Click to Expand

28 more rows

Unlocks

Capabilities are unlocked when a credit card is added to the account.

COMPARE

Free Trial

Edge Cloud

Private Fleets

FEATURES

Analytics & Monitoring

Billing Alarms

Click to Expand

28 more rows

Unlocks

Capabilities are unlocked when a credit card is added to the account.