Trying to implement keep alive background thread in Unity but keep getting client timeout

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Realtime.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Trying to implement keep alive background thread in Unity but keep getting client timeout

ryan1234
2022-09-17 22:37:54

When a new scene loads in our game the main thread pauses and this causes the connection to timeout. I've tried creating a background thread that runs SendOutgoingCommands and DispatchIncomingCommands while loading but it doesn't seem to help at all, it still times out. We are using the Photon Realtime AP

Thanks

EDIT, FURTHER HELP NEEDED: i'm able to keep the connection alive now by periodically sending messages, and calling the dispatch and send commands in a separate thread, however, is there a way to only dispatch the commands required to keep the connection alive in the separate thread? because other kinds of commands have callbacks that can only be run in the unity main thread

Comments

Tobias
2022-09-28 09:49:36

You could have a look at the ConnectionHandler. Pass a LoadBalancingClient to it and call StartFallbackSendAckThread(). This should help keep the connection while loading (unless you load much longer than the time configured via KeepAliveInBackground.

You don't need to send messages explicitly to keep the connection alive. That's done internally via pings and you don't need to dispatch anything this way, too.

Back to top