#Is there a way to do a keep alive ping type thing from a separate thread, to prevent disconnects?

42 messages · Page 1 of 1 (latest)

fleet anvil
#

I am developing for the Meta Quest which requires when you remove your headset you don't get disconnected, and they say "Avoid disconnection by implementing keep-alive networking on a separate thread"

topaz rose
#

Mirror already has a Ping-Pong exchange as long as the client doesn't go to sleep. if it does, it wouldn't matter what thread that was on.

fleet anvil
topaz rose
#

nonsense. If the app goes to background / sleep all threads would be suspended

fleet anvil
mild laurel
#

"User stays connected for at least 1 minute."

#

Try setting KCP timeout to cover that, then test?

fleet anvil
topaz rose
fleet anvil
#

So I'm trying to figure out how to match the requirements of what Quest tells developers to do, ie the link I sent that says a background thread for some reason

topaz rose
fleet anvil
topaz rose
fleet anvil
topaz rose
#

That makes it a Quest or Unity bug we can't overcome without extending the timeout as mentioned on the transport.

fleet anvil
#

I know you said you don't think it will work as the game should pause background threads too, but is it possible? If its possible to do a background thread keep alive, then I can at least test it to verify

topaz rose
# fleet anvil I know you said you don't think it will work as the game should pause background...

You can try a coroutine or InvokeRepeating that call a Command > TargetRpc from player every 5 seconds, and log it on server to see if it keeps appearing with headset removed / menu open. Since Unity is single threaded, I suspect that will also suspend, but you're welcome to try. Their "guidance" probably doesn't take into account single-threaded environments like Unity. They're more likely considering a real .Net app

fleet anvil
#

Unity CAN run different threads, but their own API is limited to the main thread

#

So a networking system, if not reliant on Unity APIs, can run on a separate thread for a keep alive ping

topaz rose
fleet anvil
topaz rose
#

you're in a custom mono world, not in .Net FW / .Net Core - threading is trash in unity

fleet anvil
topaz rose
#

Mirror isn't your problem, so maybe stop blaming us for Unity's shortcomings?

fleet anvil
topaz rose
#

There are Tasks, but I don't know of Unity has them tied to the main thread or not

fleet anvil
topaz rose
#

even with a Task, you've got to get to Mirror and send a msg on the network to have it kept alive, otherwise the server will time it out.

fleet anvil
topaz rose
#

yes, but you still need NetworkConnectionToServer, which inherits from NetworkConnection, which has
using UnityEngine;
in it

fleet anvil
#

Looking at Ignorance code, it does run on a separate thread. I think this should all work multithreading. Thank you for your help

topaz rose
#

🤦

fleet anvil
#

Um sorry? It's not like I know the internal code of Mirror and that Ignorance has its own keep alive code? I figured that was a Mirror thing, and the transport is just how its sent

topaz rose
#

Early on Jesus told you to change the KCP timeout - that would've been a good time to mention you weren't using KCP.

#

every transport has its own keep alive mechanism

#

Mirror is agnostic about transports.