Developer Documentation

Port Configurations

Each server that should be accessible from the outside needs to expose ports. Gameservers often have multiple ports doing different things. For example, a game server might have a port for the game itself, a port for the query protocol, and a port for the RCON protocol.

When developing your server, you can just hardcode the port numbers as you like. When we start your server, the runtime will iterate over all the ports that you have configured and find a free port on the host and map the container port to the host port.

graph TD
    Client-->|Connects to Host|Host[Host on port 34727]
    Host-->|Port Mapping|Server
    subgraph Container
        Server[Server on port 7777]
    end

For certain use-cases you need to know inside the server which port is mapped to which service. For example, you might want to tell an external service (i.e. match making or master server for server browser) which port to use to connect to your server.

To do that, you can use environment variables to pass the port numbers to your server. To do that, proceed as follows:

  • Define the ports in the ports section of the server configuration.
  • Create a dynamic environment variable for each port that you want to pass to the server and give it a name.

Example

You have defined a Game Port that listens on 7777 (inside the container) via TCP and UDP. Now your gameserver needs to know what the actual outside port is. Create a new dynamic environment variable named GAME_PORT and set the type to Port Mapping and set Game Port as value.

Now you can access the port number inside the server by reading the environment variable GAME_PORT. For example if you use a bash script to write the server configuration file you can use the following code to read the port number:

#!/bin/bash
echo "Game Port is $GAME_PORT"

# Write the server configuration file
echo "GAME_PORT = $GAME_PORT" > /etc/server.cfg

Now, at runtime, the actual outside port has been determined to be 34727 and will be routet to 7777. So the etc/server.cfg you will have the following content:

GAME_PORT = 34727