Steam NAT punch in case of dedicated server

Hi,

I know that the Steam Online Subsystem is doing NAT punch, so players do not need to do port forwarding. According to internet this seems to work for listen server. Does it also work for a dedicated server?

I want to publish the client on Steam (with its App ID) and the corresponding dedicated server on Steam (as Tool with its own App ID). Then the hosting player can start the dedicated server. No need for portforwarding. Other players can connect to it. Then the hosting player starts the client and can connect to his own dedicated server (running on his own machine).

Did somebody do this once? Anything to consider?

1 Like

Done something similar and afaik, one part of it is adding some global definitions to your Client and Server Target.cs files.

Here’s with the default Spacewar and its 480 steam id as an example (assuming you’re on UE5). Try replacing with yours.

  • Client.cs:
Type = TargetType.Client;

bUsesSteam = true;

GlobalDefinitions.Add("UE_PROJECT_STEAMGAMEDIR=\"Spacewar\"");
GlobalDefinitions.Add("UE_PROJECT_STEAMSHIPPINGID=480");

ExtraModuleNames.AddRange( new string[] { "YourGame" } );
  • Server.cs:
Type = TargetType.Server;

bUsesSteam = true;
bUseLoggingInShipping = true; // I think host players will need logging

GlobalDefinitions.Add("UE_PROJECT_STEAMPRODUCTNAME=\"Spacewar\"");
GlobalDefinitions.Add("UE_PROJECT_STEAMGAMEDESC=\"YourGame\"");
GlobalDefinitions.Add("UE_PROJECT_STEAMGAMEDIR=\"Spacewar\"");
GlobalDefinitions.Add("UE_PROJECT_STEAMSHIPPINGID=480");

ExtraModuleNames.AddRange( new string[] { "YourGame" } );

Assuming the rest of steam setup is done correctly on your project, these should work.
Now if your game is on UE4, I think you need to change ‘UE’ to ‘UE4’ in the GlobalDefinitions strings but I am not entirely sure.

Thanks for your answer.

I get the following log message when trying to join the dedicated server (running on my own machine):

[483]LogOnlineSession: Warning: STEAM: Failed to respond IP:MyPublicIP

I started Steam on my machine, then started the dedicated server (IDE artefact, not by Steam). Its creating a session without any warnings. Then I started the client on the same machine (IDE artefact, not by Steam) and tried to connect by using the SessionInterface->FindSessions method.

What am I missing?

  • Target.CS files are adjusted with the GlobalDefinitions, for both Client and Server I set App ID = MyClientAppID
  • Client running on port 7778, dedicated server on port 7777
  • Manual port forwarding for both port 7777 and 27015 , didnt help
  • DefaultEngine.ini:

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=MyClientAppID
SteamAppId=MyClientAppID
GameServerQueryPort=27015
bAllowP2PPacketRelay=true

[OnlineSubsystem]
DefaultPlatformService=Steam

[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName=“GameNetDriver”,DriverClassName=“OnlineSubsystemSteam.SteamNetDriver”,DriverClassNameFallback=“OnlineSubsystemUtils.IpNetDriver”)

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName=“OnlineSubsystemSteam.SteamNetConnection”

  • Session creation parameters:
FOnlineSessionSettings SessionSettings;
SessionSettings.bIsDedicated = IsRunningDedicatedServer();
SessionSettings.bIsLANMatch = (IOnlineSubsystem::Get()->GetSubsystemName() == "NULL"); 
SessionSettings.NumPublicConnections = NumPublicConnections;
SessionSettings.bShouldAdvertise = true; 
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bAllowJoinViaPresence = !IsRunningDedicatedServer();
SessionSettings.bUsesPresence = !IsRunningDedicatedServer();
  • Session search parameters:
SessionSearch->bIsLanQuery = (IOnlineSubsystem::Get()->GetSubsystemName() == "NULL");
SessionSearch->MaxSearchResults = 1000;

I see. At first glance it looks like a NAT issue. Do you have a single network at home ?
Also is the MyPublicIP the machine’s IP or the router’s ?. Try connecting the machine directly on the router and DMZing it.

Single network (normal home set-up). Computer is directly attached to the router. Windows firewall (even router firewall) disabled. Port forwarding done. UPnP enabled. MyPublicIP is the routers IP. I know what a DMZ is, but not sure what you mean with DMZing.

Could it be that the Steam Online Subsystem or anything related to the session making depends on having a public IPv4 address (not IPv6)?

I can connect to the dedicated server now. My new router was only doing IPv6 port forwardings, so I replaced it by my old router and now it works (by setting port forwardings for IPv4 for Steams port 27015).

But this means player need to do port forwardings, right? I thought using the Steam Subsystem would help me with that. So was this a wrong assumption?

Hm that’s totally unfortunate. It’s been so long since I swapped my router that I had no idea there are IPv6-only routers.

If memory serves me well, clients weren’t required to do any kind of port fiddling. Only the server host was. However testing both client and server on the same machine does introduce extra complexities. Are you doing shipping build btw ?

whoever is interested:

My requirement is that players do not have to do port forwarding, even if they are hosting a server.

Steam (SDK) supports this, but I couldn’t get it working using the Steam OSS plugin and the Steam Sockets Plugin.

However, after days of failures, I found this thread which seem to be highly related to what Im trying to archieve: Question about networking ports and EOS - #10 by NomNomai

EOS (SDK) implements NAT-Traversal + Relay Servers. The pre-built-in plugin for EOS doesn’t use it, but maybe this one: https://www.fab.com/listings/b900b244-0ff6-49e3-8562-5fc630ba9515 (at least one of the pictures says “No portforwarding needed”) :man_shrugging:

Update

Until anyone proves the opposite: Session making without any port forwarding is not possible when hosting a dedicated server (at least not out of the box when using Steam or EOS Plugins). You need to use the listen server model!

Answer to the original question: NAT punch etc. seems to work for the dedicated server, but its still required to open ports.