petemoss
petemoss2mo ago

Connection retry

In a situation where our app starts with poor or no internet connection, we see that Normcore will time out, and our only recourse currently is to restart our app. Is there a way to set up a reconnection system so the app keeps trying?
4 Replies
kapa.ai
kapa.ai2mo ago
Hi @petemoss. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Normcore does not provide a built-in automatic reconnection system for client-side disconnections due to poor or no internet connection, according to the available documentation. However, you can implement your own reconnection logic in Unity by listening for the didDisconnectFromRoom event on the Realtime component and then attempting to reconnect when a disconnection occurs. Here’s an example pattern, adapted from the server plugin documentation, which you can use on the client side as well:
using Normal.Realtime;

public class ConnectionManager : MonoBehaviour {
[SerializeField]
private Realtime _realtime;

private void Start() {
_realtime.didDisconnectFromRoom += DidDisconnectFromRoom;
Connect();
}

private void Connect() {
_realtime.Connect("My Room");
}

private void DidDisconnectFromRoom(Realtime realtime) {
// Try to reconnect after a delay
Invoke(nameof(Connect), 2.0f); // Wait 2 seconds before retrying
}
}
using Normal.Realtime;

public class ConnectionManager : MonoBehaviour {
[SerializeField]
private Realtime _realtime;

private void Start() {
_realtime.didDisconnectFromRoom += DidDisconnectFromRoom;
Connect();
}

private void Connect() {
_realtime.Connect("My Room");
}

private void DidDisconnectFromRoom(Realtime realtime) {
// Try to reconnect after a delay
Invoke(nameof(Connect), 2.0f); // Wait 2 seconds before retrying
}
}
This approach will keep trying to reconnect whenever a disconnection occurs, which should help in scenarios where the app starts with a poor or no internet connection. You can adjust the delay and add additional logic (such as a maximum number of retries or exponential backoff) as needed for your application. The reconnection pattern is explicitly shown for server plugins, but the same event-driven approach applies to client code as well, since the didDisconnectFromRoom event is available on the Realtime component in Unity Normcore-private Server Plugins. If you need more advanced connection management, you may need to implement additional logic yourself, as the knowledge sources do not mention a built-in client-side reconnection system. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@454336284178251778> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
petemoss
petemossOP2mo ago
awesome, thanks, i will give this a try
maxweisel
maxweisel2mo ago
we’ve got an Autoreconnect component in the works too. I expect it to ship in the next few weeks

Did you find this page helpful?