DC
DC2w ago

Catch errors on connect

How best to check if Normcore is available, or if Normcore ports are blocked, and catch these problems so I can code for them.
2 Replies
kapa.ai
kapa.ai2w ago
Hi @DC. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To check if Normcore is available or if ports are blocked, and to catch these problems, you can follow these best practices: 1. Use try-catch blocks: Wrap your connection code in try-catch blocks to handle any exceptions that might occur during the connection process. 2. Check connection status: Monitor the connection status using the Realtime.connected property or the Realtime.didConnectToRoom event. 3. Implement timeout logic: Set up a timeout mechanism to detect if the connection is taking too long. 4. Check firewall rules: Ensure that your network allows the required ports and IP ranges for Normcore. Here's a more detailed breakdown: 1. Firewall Rules: Make sure your network allows the following outbound traffic: - TCP ports 443 and 3000 to *.normcore.io - UDP ports 32,768 - 65,535 to any destination IP Normcore Firewall Rules provides more details on the required firewall configurations. 2. Connection Error Handling: When connecting to a room, use try-catch blocks to handle potential exceptions:
try
{
realtime.Connect();
}
catch (Exception e)
{
Debug.LogError("Failed to connect: " + e.Message);
// Handle the error (e.g., show a message to the user, retry connection, etc.)
}
try
{
realtime.Connect();
}
catch (Exception e)
{
Debug.LogError("Failed to connect: " + e.Message);
// Handle the error (e.g., show a message to the user, retry connection, etc.)
}
3. Connection Status Monitoring: You can check the connection status using the Realtime.connected property or by subscribing to the Realtime.didConnectToRoom event:
realtime.didConnectToRoom += (room) => {
Debug.Log("Connected to room!");
};

// Or check the status periodically
if (realtime.connected)
{
Debug.Log("Connected to Normcore");
}
else
{
Debug.Log("Not connected to Normcore");
}
realtime.didConnectToRoom += (room) => {
Debug.Log("Connected to room!");
};

// Or check the status periodically
if (realtime.connected)
{
Debug.Log("Connected to Normcore");
}
else
{
Debug.Log("Not connected to Normcore");
}
4. Implement Timeout Logic: Set up a coroutine to implement a connection timeout:
private IEnumerator ConnectionTimeoutCoroutine()
{
float timeoutDuration = 10f; // Adjust as needed
float elapsedTime = 0f;

while (!realtime.connected && elapsedTime < timeoutDuration)
{
elapsedTime += Time.deltaTime;
yield return null;
}

if (!realtime.connected)
{
Debug.LogError("Connection timed out");
// Handle the timeout (e.g., retry connection, show error message)
}
}

// Start the coroutine when attempting to connect
StartCoroutine(ConnectionTimeoutCoroutine());
private IEnumerator ConnectionTimeoutCoroutine()
{
float timeoutDuration = 10f; // Adjust as needed
float elapsedTime = 0f;

while (!realtime.connected && elapsedTime < timeoutDuration)
{
elapsedTime += Time.deltaTime;
yield return null;
}

if (!realtime.connected)
{
Debug.LogError("Connection timed out");
// Handle the timeout (e.g., retry connection, show error message)
}
}

// Start the coroutine when attempting to connect
StartCoroutine(ConnectionTimeoutCoroutine());
By implementing these strategies, you can effectively detect and handle connection issues with Normcore, including port blocking and availability problems. If you're still experiencing issues after implementing these solutions, you may want to check your logs for specific error messages. The Platforms Common Questions section in the Normcore documentation provides additional troubleshooting steps for specific scenarios. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@1259730396577529917> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?