Gamelift returning the same IP address for different game session?

Hi all, I would like to ask how should I properly set up the fleet/game session setting on AWS Gamelift. Currently, I am facing a problem that is a player will be given the same IP address even though they are allocated to another game session.

We are using UE4 to develop our game. Players can do the matchmaking and then they can use the returning result (IP address) to join into the game server. We had done these so far. However, the problem is, players who are allocated to different game sessions will receive the same IP address for them to join, which make them finally join into the same game session. In my understanding, an instance can run more than one game server process(game session), but how can I do so? by specifying the port? how?

Hey @TowardGames,

Each server process should listen for connections on a different port. During the ProcessReady() call on the server, the process should tell GameLift which port it is listening on. The server appears to be telling GameLift that it is listening on Port 7777 regardless of what port it is actually listening on. Code to do this correctly is pasted below.


#include <tchar.h>
#include <string.h>
#include <iostream>
#include <random>
#include <winsock2.h>
std::random_device rng;
void ProcessReady(int port)
{
std::cout << ":) Selected port: " << port << std::endl;
}
void PortSelect(int argc, _TCHAR* argv[])
{
std::cout << ":) START" << std::endl;
int lowerPort = 3333;
int upperPort = 3353;
try
{
// if you want to receive the low port and the high port from the command line, e.g. server.exe 3333 3533
if (argc != 3) throw ":( Invalid command line arguments";
lowerPort = _tstoi(argv[1]);
upperPort = _tstoi(argv[2]);
}
catch (...) {}
if (lowerPort>upperPort) throw ":( Invalid port range";
std::uniform_int_distribution<int> distribution(lowerPort, upperPort);
int selectedPort = distribution(rng); // generates number in the range lowerPort..upperPort
bool connected = false;
int lastPort = selectedPort;
while (!connected)
{
struct sockaddr_in serv_addr;
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) throw "ERROR opening socket";
memset(&serv_addr, '\0', sizeof(serv_addr));
int portno = selectedPort;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
{
std::cout << ":| Occupied port: " << selectedPort << std::endl;
selectedPort++;
if (selectedPort > upperPort)
{
selectedPort = lowerPort;
}
if (selectedPort == lastPort)
{
std::cout << ":( No free ports" << std::endl;
return;
}
}
else
{
connected = true;
}
}
ProcessReady(selectedPort);
//PortSelect (argc, argv); // Call self repeatedly to exhaustively open all ports until none are left. (for testing)
}
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize Winsock
WSADATA wsaData;
int iResult; // Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed with error: %d\n", iResult);
return 1;
}
// Select a port
PortSelect(argc, argv);
return 0;
}