Photon Networking call many times Service();

53 Views Asked by At

According to the following link https://doc.photonengine.com/realtime/current/reference/performance-tips it is recommended to call service() several times, but I wanted to know how many times would be ideal? Because in my app this caused me to exit the game.

private void ServiceLoop()
    {
        int timeMill = 20000;
        while (isServiceRunning)
        {
            if (PhotonNetwork.NetworkingClient != null)
            {
                PhotonNetwork.NetworkingClient.Service();

                // if (PhotonNetwork.NetworkingClient.LoadBalancingPeer.SendOutgoingCommands())
                // {
                //     Debug.LogException(new       System.Exception("LoadBalancingPeer.SendOutgoingCommands()"), this);
                //     PhotonNetwork.SendAllOutgoingCommands();
                // }

                System.Threading.Thread.Sleep(timeMill);
            }
        }
    }

We expected less photon disconnection when calling service() multiple times.

1

There are 1 best solutions below

0
Kaiserludi On

How many times exactly you should call Service() depends on your game, but usually 10-20 times a second is best.

Your value of 20000 for timeMill is WAY to high. When you don't call it more often than once every 20 seconds, then you are guaranteed to experience a timeout disconnect, as the the server disconnects clients that don't send any life signs for 5-10 seconds and the client only sends from inside of Service() (or rather SendOutgoingCommands(), which is called by Service(), but can alternatively also be called by your code).

Changing the value of timeMill to 100 should fix the issue.