Server Port

Hey there, i searched the wiki desperately but i wasnt able to find any way to obtain the port that the current server instance is bound to… Is someone able to provide me a way of obtaining the port?

found it after digging deep inside the engine code:

GameMode Code:

if (GetWorld()->IsServer())
		return GetWorld()->URL.Port;
	return 0;

(Install Directory)\Engine\Config\BaseEngine.ini has the various port numbers.

yeh but does it contain the port a server is actually listen to? like if you start it with the -PORT=xxxx parameter?

It contains the default port info:

Which is read in by FUrlConfig::Init

So, yea, I think your way of grabbing it from the world is fine. It looks like you could also just call FURL::UrlConfig.DefaultPort since it’s statically initialized. Not sure what the difference between the port in FURL and FUrlConfig is. Both seem to inherit whatever is passed from the command line.

Did you end up creating a custom class for this and if so would you be willing to share the code?
I’ve been struggling to get this to work in C++. Thanks.

I would suggest making use of


as @ruohki said. This will return the port the game is actively listening to (whether its INI or passed through parameter). Another good thing about this is if you are using multiple servers at the same time then each server will automatically change the port number to the next available one. For example if you run one dedicated server listening to 7777 and run another one at the same time then second server will listen to 7778. If you run a third one it will listen to 7779 and so on (atleast this is what I get on AWS servers). So basically you can have one computer running multiple dedicated servers listening to different ports.

I have problems with AWS Servers and port change. My problem is that my IpNetDriver was not ready in Gamemode constructor and has not newest port assigned yet. So GetWorld()->URL.Port gets only port 7777. Is there some event to help me with this problem? I Tried to delay port assign process but received ERROR status on Gamelift

@AdeptStrain and all, i need to split the udp and tcp to run on different ports to get it to work inside of azure container instances. Do you have any idea how to achieve this in the source?