I am facing problem with my online multiplayer board game. It takes long time to create and join room. Also sometimes other player doesn't get the data. After searching all over the Photon C++ code I found this function :

void NetworkLogic::onAvailableRegions(const ExitGames::Common::JVector<ExitGames::Common::JString>& availableRegions, const ExitGames::Common::JVector<ExitGames::Common::JString>& availableRegionServers)
    EGLOG(ExitGames::Common::DebugLevel::INFO, L"%ls / %ls", availableRegions.toString().cstr(), availableRegionServers.toString().cstr());
    mpOutputListener->writeLine(L"onAvailableRegions: " + availableRegions.toString() + L" / " + availableRegionServers.toString());
    // select first region from list
    mpOutputListener->writeLine(L"selecting region: " + availableRegions[0]);

In the last line its just passing 0th region of the available regions. I think that region could be the slower one. Anyways, I am still facing the problem and I need help. Thanks.


1 Answer 1


The optional Listener::onAvailableRegions() callback only gets called, when you pass RegionSelectionMode::SELECT to the Client constructor. This approach is useful when you have special criteria for which region you want to choose or when you already know your preferred region. If you simply want to connect to the region with the lowest ping of all available server regions, then please use RegionSelectionMode::BEST instead. In that case your onAvailableRegions() implementation won't get called, but instead the client on receiving the list of available regions automatically sends a couple of pings to each of them and then continues with connecting to the region which had the lowest average ping result.

Please note that pinging takes a moment as the Client sends several pings (5 per region) to all available server regions of which some are located at the other end of the world. Therefor when pinging occurs, then the time for the initial connect() call on a freshly created Client instance will take up to 4 seconds longer than normal. For this reason the Client caches the ping result and directly uses the cached value for further connections. However the Client does not store the ping result (which can be retrieved by a call to Client::getRegionWithBestPing() (only after you have successfully connected with RegionSelectionMode::Best - in all other cases it just returns an empty string) ) in permanent memory so that your app should store it in a file.

This way your app can check if it already has a stored best region and then just use RegionSelectionMode::SELECT and pass the region code for this stored region to selectRegion() to shorten the time that is needed for the initial connection of a newly created Client instance considerably. You only should use RegionSelectionMode::BEST, if your app does not have a stored region yet, or if the user through your game UI explicitly requests to re-ping all regions.

In your stack exchange profile it says that you are located in India. The region at index 0 usually is the European region that is hosted in Amsterdam and the ping between Western Europe and most of Asia is rather high. Choosing the Indian region that is hosted in Chennai (the one with the "in" token) should give you a lot better results.

You can find the list of available regions, their tokens and where each of them is hosted at https://doc.photonengine.com/en-us/realtime/current/reference/regions


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .