C++ SDK How to select region?
Options
Best Answer
-
Hi Jo.
1.
Make sure, that you connect to Photon Cloud. Cloud regions are not supported by Photon Server.
2.
The Constructor of class LoadBalancing::Client has a couple of optional parameters. The last one of them is of type bool, called 'useDefaultRegion' and defaults to 'true'. Please explicitly pass 'false' for that parameter.
3.
During the connect flow that is triggered by your call to Client::connect(), the client receives a list of available regions from the name server.
LoadBalancing::Listener declares an optional callback Listener::onAvailableRegions(). If you have passed 'false' for 'useDefaultRegion', then the Client won't automatically choose the first item in that list of available regions, but pass the list to that callback.
Therefor in your Listener implementation you should override the empty default implementation of that callback with a meaningful implementation that selects a region based on whatever criteria you can come up with.
4.
The connect flow pauses entirely until you have chosen a region.
5.
Pass your chosen region to Client::selectRegion() to continue the connect flow.
Note:
Client::selectRegion() is only expected to be called after you have received a call to Listener::onAvailableRegions() (call selectRegion()either directly from within this callback or later, after the callback has been returned). Otherwise the Client won't be at the correct stage of the connection-flow for region selection.
An example implementation of Listener::onAvailableRegions() can be found in the source code of demo_loadBalancing inside the SDK.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"onAvailableRegions: %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]); mLoadBalancingClient.selectRegion(availableRegions[0]); }
5
Answers
-
Hi Jo.
1.
Make sure, that you connect to Photon Cloud. Cloud regions are not supported by Photon Server.
2.
The Constructor of class LoadBalancing::Client has a couple of optional parameters. The last one of them is of type bool, called 'useDefaultRegion' and defaults to 'true'. Please explicitly pass 'false' for that parameter.
3.
During the connect flow that is triggered by your call to Client::connect(), the client receives a list of available regions from the name server.
LoadBalancing::Listener declares an optional callback Listener::onAvailableRegions(). If you have passed 'false' for 'useDefaultRegion', then the Client won't automatically choose the first item in that list of available regions, but pass the list to that callback.
Therefor in your Listener implementation you should override the empty default implementation of that callback with a meaningful implementation that selects a region based on whatever criteria you can come up with.
4.
The connect flow pauses entirely until you have chosen a region.
5.
Pass your chosen region to Client::selectRegion() to continue the connect flow.
Note:
Client::selectRegion() is only expected to be called after you have received a call to Listener::onAvailableRegions() (call selectRegion()either directly from within this callback or later, after the callback has been returned). Otherwise the Client won't be at the correct stage of the connection-flow for region selection.
An example implementation of Listener::onAvailableRegions() can be found in the source code of demo_loadBalancing inside the SDK.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"onAvailableRegions: %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]); mLoadBalancingClient.selectRegion(availableRegions[0]); }
5 -
It works.
Thanks a lot!0