Skip to main content

Transports & Samples

After managing your players with either a matchmaker or lobbies then creating a relay session for them using the Edgegap API, you will need to connect your players to the relay once it is ready. Edgegap offers a specific transport to do just that, and this guide will show you how to implement it in your project. The transport is available here on our GitHub.

With Unity, there currently is a version of the transport for the following netcodes:

  • Mirror;
  • Fishnet;
  • Unity Netcode for GameObjects (NGO).

Adding the transport

After downloading the right transport for your netcode, you need to include it in your project. First, add it to your project files in the following location:

  • Mirror : add the Edgegap folder under Assets/Mirror/Transports;
  • Fishnet : add the Edgegap KcpTransport folder under Assets/Fishnet/Plugins;
  • NGO : add the EdgegapRelay folder under Assets/Edgegap.

Then, add the EdgegapKcpTransport script to your NetworkManager gameObject, make sure to drag that new component in the Transport property of the gameObject as well.


If the option is present, make sure to disable Relay GUI in the EdgegapKcpTransport component of the NetworkManager. Otherwise, it will interfere when attempting to connect to the relay.

This option is namely present in the Mirror and NGO versions of the transport.

Connecting to the relay

After matchmaking and creating the relay session, use the Edgegap API to determine when the relay is ready to accept connections. Once it is, use the data provided in the API response to set the values of the transport. You will need the following values in the appropriate fields:

  • the relay's IP address is used as the transport's relay address;
  • the relay's client port value is used as the transport's relay port when connecting a client;
  • the relay's server port value is used as the transport's relay port when connecting the server/host;
  • the session authorization token is used as the transport's session ID;
  • the user's authorization token is used as the transport's user ID.

Each player will have their own unique authorization token, but the session token will remain the same for each player in the session.

// `data` is the deserialized API response converted to JSON
// `_EdgegapTransport` is the EdgegapKcpTransport

// Convert uint? to uint
uint sessionAuthorizationToken = data.authorization_token ?? 0;

//TODO find which session user matches the player, `i` being its place in the list
uint userAuthorizationToken = data.session_users?[i].authorization_token ?? 0;


// then `NetworkManager.Singleton.StartHost();` if host player
// OR `NetworkManager.Singleton.StartClient();` if client

Once the values are properly set, use the transport to connect each player to the relay. After a short moment, you will be able to play the game!

Sample projects

The following projects are simple examples that use the Edgegap relay transport.

For them to work properly, open a command prompt terminal and download the project via the git clone [URL] command. Open the project folder in the editor via the Unity Hub, then change the RelayProfileToken value in the HelloWorldManager component of the NetworkManager gameObject to your own relay profile token.