How to assign unique port numbers (Unity Game Engine)

Hello again. Firstly, I would like to say this forum has helped out a lot so thank you all :smiley:

I am coming to you once again to ask for help. Currently, in my project, users can create game sessions and using Filter expressions, get the ip and Port number, then join the session using the ip and port.

My question is, how can I assign a unique port number to each game session? I am currently able to assign unique port numbers on my local server but not in game lift? Is there a simple way (in c#) for me to assign a unique port number in gamelift?

For example:
-First game sessions gets created, port number assigned is 7777
-Second game session gets created, port number 7778 is assigned

Thank you in advance to anyone who took the time to read this post and to offer help :smiley:

The simplest way to do this is via your fleetโ€™s runtime configuration:

  1. Make sure the correct port ranges are open on the fleet in your create fleet call via the --ec2-inbound-permissions settings

  2. Provide a launch configuration per server

aws gamelift create-fleet ... 
--runtime-configuration "GameSessionActivationTimeoutSeconds=300,ServerProcesses==[{LaunchPath='C:\game\MyGame.exe',Parameters=port 33435,ConcurrentExecutions=1},{LaunchPath='C:\game\MyGame.exe',Parameters=port 33436,ConcurrentExecutions=1}]"
  1. Here a fleet will have two servers per instance. Each server will get started with a specific set of parameters. On launch server uses the passed port parameter and binds to the port

  2. Report the port the server is listening on in your ProcessParameters in the ProcessReady callback.

You can of course dynamically set the server port (ie your servers start up and figure out what port they should use via other mechanisms), which simplifies the runtime configuration settings.

The only really important is to tell which port a server is on to GameLift via the ProcessParams (and obviously make sure your server is actually running on that port and the port is open on the fleet).