We are integrating photon load balancing for real time games but not moving ahead from connecting.
We have tried with sample app provided for load balancing but stuck at connection state
mpOutputListener->writeLine(L"connecting to Photon");
#if defined _EG_XB1_PLATFORM || _EG_GAMECORE_PLATFORM
mReauthenticateRequired = false;
#elif defined _EG_SWITCH_NX_PLATFORM
authValues.setType(ExitGames::LoadBalancing::CustomAuthenticationType::NINTENDO_SWITCH).setParameters(ExitGames::Common::JString(L"appversion=1") + L"&token=" + mIDToken);
#elif defined _EG_PS4_OR_NEWER_PLATFORM
# if defined _EG_PS4_PLATFORM
# elif defined _EG_PS5_PLATFORM
authValues.setParameters(L"token=" + AuthenticationParameters::get().authCode + L"&env=" + AuthenticationParameters::get().env + L"&userName=" + AuthenticationParameters::get().userID);
#else // we could still set the userID when doing console authentication, but it would be pointless, as the server would override it with the userID that is set by the auth-provider, anyway. Hence we only set it in the #else case
if(mUserID.length()) // if we don't have a user ID yet, let the server assign one for us, afterwards store the assigned value in mUserID in connectReturn() and re-use it in subsequent connects, so that Photon recognizes us as the same user
What do you mean with "stuck"? Does it log an error after a couple of seconds or does is just hang?
Have you entered a valid appID in the demo source?
I assume that aside from the appID you are testing with an unmodified demo. Is that correct?
Have you verified that the app isn't blocked by your firewall or router? Please make sure that your firewall and router both allow outgoing traffic on the ports listed at https://doc.photonengine.com/en-US/realtime/current/connection-and-authentication/tcp-and-udp-port-numbers (note that on default demo_loadBalancing, the demo that your code snippet is from, uses UDP, with 'useAlternativePorts' set to false and 'tryUseDatagramEncryption' set to true - this means means, that it uses ports 5055, 5056 and 5058 for UDP and port 19093 for WSS).
Does it help, if you set 'useAlternativePorts' to true or if you switch the conenction protocol to TCP or WSS (don't forget to permit traffic on the according ports as well when you test this)?
Furthermore please also check if it works from another network (i.e. try from home if it doesn't work from your office, to check if the the office network is the culprit).0
1. It's stuck on connecting state, not showing any error
2. Yes entered correct app Id
3. Modified main project, because it was not compatible with Android studio, but not modified other classes excluding cmake file
4. Tried on multiple networks
5. Tried with useAlternativePorts and TCP after your suggestion but it's still not working0
Modified main project
Can you please verify that the lines
StdUI::main_loop(void)do still get called, especially the line
at the very end of
NetworkLogic::run(void)is critically. If it does not get called regularly, then the Client will just stay stuck in the connecting state. Also after the connection got established it's still critical that
service()gets called regularly.
In that case please also make sure that the app got internet permission from the OS.0
Thanks for your prompt response, After your suggestion We called run() method regularly until the connection got established. So kind of the issue has been resolved at our end. But I have 2-3 doubts so I am listing down them here.
- So to establish connection We have to call run() method regularly, so according to my observation this process taking around 5 seconds. As of now I am planning to establish connection when user is clicking on Play online button but due to this delay Should I establish connection on App startup ?
- if We establish connection for all users on app startup, does this increase CCU ??
After your suggestion We called run() method regularly until the connection got established.
As I have mentioned before, you need to continue to call it regularly even after the connection got established. You can stop doing so after you called disconnect() and have received a call to disconnectReturn() (don't sop calling it right after you call to disconnect() - otherwise the client won't be able to inform the server about the disconnect and it will continue to appear online for other clients until it times out after 5-10 seconds). service() keeps the connection alive and is responsible for actually sending and receiving messages (the term "messages" includes your own operation requests, like joining and leaving rooms or sending events to other clients, but also internal messages for establishing the connection).
so according to my observation this process taking around 5 seconds.
The connection-process should only take this long when you are using RegionSelectionMode::BEST, which involves sending several pings to every available region to find out to which one the client has the best ping.
Set 'useBestRegion' to false to prevent the demo from pinging on the first connect after every restart of the application.
Let me quote a comment in one of the first lines of NetworkLogic.cpp on this topic:
// pinging takes a moment, so for a real game it makes sense to retrieve the best region with getRegionWithBestPing(), store it in a file, use RegionSelectionMode::SELECT and pass that region to selectRegion() and to only use RegionSelectionMode::BEST, if no best region has been determined yet or if the player explicitly requests to repeat pinging
As of now I am planning to establish connection when user is clicking on Play online button but due to this delay Should I establish connection on App startup ?
If the game can be played offline, then I would only establish the connection once the player has clicked on the 'Play online' button.
if We establish connection for all users on app startup, does this increase CCU ??
Each connected client counts against the CCU, so if there is a significant amount of users that starts the app, but does not play online or at least does not play online for some time after starting the app, then yes, establishing a connection on app startup right away will impact your CCU.
As you have mentioned Android in a previous reply:
You might want to consider disconnecting players when they put the app into the background and reconnecting them once they put it back to the foreground.
You can use reconnectAndRejoin() to have the client attempt to rejoin a room that it has been in at the time of the disconnect and that it has not left for good (see the reference doc for reconnectAndRejoin() for details).
In case that you also want to support iOS:
Please be aware that Apple does not give any execution time to games while they are in the background, so on iOS you absolutely must disconnect when the OS informs you that your app is going to the background. Otherwise the client will appear online until it times out after 5-10 seconds.0