stride3d/stride · error · SimpleSocketException
Could not connect to server
Error message
Could not connect to server
What it means
RouterClient.RequestServer throws SimpleSocketException when the router's reply is not ClientRouterMessage.ServerStarted, meaning the router refused or failed to start the requested server. The connection was made, but the handshake result was a negative/other message.
Solutions
- Verify the router service is running and accepting connections.
- Check the serverUrl passed to RequestServer is correct and registered on the router.
- Inspect the errorCode/error message handling path to log the router's reason and retry.
- Add retry logic with backoff around RequestServer for transient network failures.
Example fix
// before
var conn = await routerClient.RequestServer("tcp://myhost:12345");
// after
SimpleSocketException ex = null;
for (int i = 0; i < 3; i++)
{
try { var conn = await routerClient.RequestServer(serverUrl); break; }
catch (SimpleSocketException e) { ex = e; await Task.Delay(1000 * (i + 1)); }
} Defensive patterns
Strategy: retry
Try / catch
try { conn = await router.RequestServer(serverUrl); }
catch (SimpleSocketException e) { /* inspect router health / retry with backoff */ } Prevention
- Health-check the router before requesting servers.
- Validate the serverUrl format and registration on the router.
- Implement retry with exponential backoff for transient failures.
When it happens
Trigger: RequestServer sends the serverUrl, reads a ClientRouterMessage that isn't ServerStarted — e.g. router rejected the request, returned an error message, or the protocol got out of sync.
Common situations: Router service not running properly or unreachable relay backend; wrong server URL given to the router; network interruption causing a truncated/garbled response message.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- Connection router did not connect back to our listen socket
- Invalid ack
- Socket closed
- Cannot listen on an unusable interface. Check the IsUsable…
- Could not restore package
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/53641498ba920cd0.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Engine/Engine/Network/RouterClient.cs:54
/// <summary>
/// Requests a specific server.
/// </summary>
/// <returns></returns>
public static async Task<SimpleSocket> RequestServer(string serverUrl, CancellationToken cancellationToken = default(CancellationToken))
{
var socketContext = await InitiateConnectionToRouter().ConfigureAwait(false);
using (cancellationToken.Register(() => socketContext.Dispose()))
{
await socketContext.WriteStream.WriteInt16Async((short)ClientRouterMessage.RequestServer).ConfigureAwait(false);
await socketContext.WriteStream.WriteStringAsync(serverUrl).ConfigureAwait(false);
await socketContext.WriteStream.FlushAsync().ConfigureAwait(false);
var result = (ClientRouterMessage)await socketContext.ReadStream.ReadInt16Async().ConfigureAwait(false);
if (result != ClientRouterMessage.ServerStarted)
{
throw new SimpleSocketException("Could not connect to server");
}
var errorCode = await socketContext.ReadStream.ReadInt32Async().ConfigureAwait(false);
if (errorCode != 0)
{
var errorMessage = await socketContext.ReadStream.ReadStringAsync().ConfigureAwait(false);
throw new SimpleSocketException(errorMessage);
}
}
return socketContext;
}
/// <summary>
/// Initiates a connection to the router.
/// </summary>
/// <returns></returns>
private static async Task<SimpleSocket> InitiateConnectionToRouter()View on GitHub (pinned to 96fad776d2)