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

ryan1234
ryan1234
edited September 18 in DotNet

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

Answers

  • Tobias
    Tobias admin
    edited September 28

    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.