Okay, let's walk through a practical example of setting up and running a game where players can host their own dedicated server, contrasting it with the more common "listen server" approach.
We'll use a hypothetical game called "MyAwesomeUEGame" and assume our main gameplay map is located at /Game/Maps/MyGameMap.
Understanding the Concepts First:
-
Listen Server:
- A single player's game client also acts as the server.
- It's the simpler player-hosted model because only one executable (
.exe) is needed.
- The host player is "in" the game world and playing alongside everyone else.
- Pros: Easy to set up for players, no separate download.
- Cons: Performance can suffer if the host's machine is busy playing and serving. The host leaving disconnects everyone. Can be more susceptible to cheating if the host is compromised.
-
Dedicated Server:
- A separate, standalone executable (e.g.,
MyAwesomeUEGameServer.exe) that only runs server logic. It has no rendering, no player input (beyond admin commands), and no game simulation on the client side.
- Players connect to this dedicated server process.
- Pros: Better performance and stability (server resources aren't shared with a client). Host can disconnect without affecting the game session. Potentially more secure against certain types of cheating.
- Cons: Requires players to obtain and run a separate server executable. Requires players to understand port forwarding and potentially firewall configurations.
The Example Scenario: Player-Hosted Dedicated Server
Let's say you've followed the setup steps mentioned previously: your UE project is C++, you've enabled the Server target, and you've built or packaged a dedicated server build.
You now have two main executables:
MyAwesomeUEGame.exe (The Client/Game executable)
MyAwesomeUEGameServer.exe (The Dedicated Server executable)
Step 1: The Host Player (Player A) Launches the Dedicated Server
Player A wants to host a game for their friends. They need to run the dedicated server executable.
-
Locate the Server Executable: Player A finds MyAwesomeUEGameServer.exe (it would be in YourProject/Binaries/Win64 if built directly, or within the packaged server folder).
-
Open a Command Prompt/Terminal: Player A navigates to the directory containing MyAwesomeUEGameServer.exe.
-
Launch with Arguments: Player A types the following command:
# On Windows:
MyAwesomeUEGameServer.exe /Game/Maps/MyGameMap -log
# On Linux (assuming it's compiled for Linux):
./MyAwesomeUEGameServer /Game/Maps/MyGameMap -log
MyAwesomeUEGameServer.exe: This tells the system to run the dedicated server executable.
/Game/Maps/MyGameMap: This is the map the server should load and start the game session on. (Note: Unreal often uses /Game/ prefix for cooked maps).
-log: This is crucial for debugging. It sends server output to the console window, showing connection attempts, errors, etc.
-
Port Forwarding (Crucial for Player A):
- If Player A is hosting from their home network, they must configure their router to forward the game's network port (default is
7777 for UDP and TCP) to their computer's local IP address. Without this, other players won't be able to connect from the internet.
Step 2: Other Players (Player B, Player C, etc.) Connect to Player A's Dedicated Server
Now, Player B (and others) want to join Player A's game. They will use the standard game client executable.
-
Obtain Player A's Public IP: Player A needs to tell Player B their public IP address (which they can find by searching "what is my IP" on Google). Let's say Player A's public IP is 123.45.67.89.
-
Launch the Game Client: Player B runs their MyAwesomeUEGame.exe.
-
Open a Command Prompt/Terminal: Player B navigates to the directory containing MyAwesomeUEGame.exe.
-
Connect with Arguments: Player B types the following command:
# On Windows:
MyAwesomeUEGame.exe 123.45.67.89:7777
# On Linux:
./MyAwesomeUEGame 123.45.67.89:7777
MyAwesomeUEGame.exe: This tells the system to run the standard game client.
123.45.67.89: Player A's public IP address.
:7777: The port the dedicated server (Player A's machine) is listening on.
Contrasting with the Listen Server Example
If Player A were hosting a listen server instead:
-
Player A (Host) launches:
# On Windows:
MyAwesomeUEGame.exe /Game/Maps/MyGameMap -log -listen
(Note the -listen flag, which tells the client executable to also act as a server).
-
Player B (Client) connects to Player A's listen server:
# On Windows:
MyAwesomeUEGame.exe 123.45.67.89:7777
(The connection command is identical for connecting to a listen server or a dedicated server, assuming they use the same port).
Key Differences Summarized:
| Feature | Listen Server Host (Player A) | Dedicated Server Host (Player A) | Other Players (B, C, etc.) |
|---|
| Executable Run | MyAwesomeUEGame.exe | MyAwesomeUEGameServer.exe | MyAwesomeUEGame.exe |
| Launch Command | /Game/Maps/MyGameMap -log -listen | /Game/Maps/MyGameMap -log | [HostIP]:7777 |
| Host Role | Plays game AND acts as server | ONLY acts as server (or runs server in background) | Connects to the server |
| Player A's Setup | Run game, tell friends IP. (Simpler) | Run server exe, port forward. (More complex setup) | Run game, connect to Host IP. |
| Server Process | Integrated into the client process | Separate, independent process | Connects to the server |
In essence, for player-hosted dedicated servers:
- You distribute the
YourGameServer.exe binary.
- The player who wants to host runs that server binary.
- Other players run the normal
YourGame.exe and connect to the host's IP and port.
- The host player is responsible for port forwarding and keeping the server executable running.
This is a viable model, but it places a higher technical burden on the player who chooses to host.