{"record":{"id":"53641498ba920cd0","repo":"stride3d/stride","slug":"could-not-connect-to-server","errorCode":null,"errorMessage":"Could not connect to server","messagePattern":"Could not connect to server","errorType":"exception","errorClass":"SimpleSocketException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Engine/Network/RouterClient.cs","lineNumber":54,"sourceCode":"\n        /// <summary>\n        /// Requests a specific server.\n        /// </summary>\n        /// <returns></returns>\n        public static async Task<SimpleSocket> RequestServer(string serverUrl, CancellationToken cancellationToken = default(CancellationToken))\n        {\n            var socketContext = await InitiateConnectionToRouter().ConfigureAwait(false);\n\n            using (cancellationToken.Register(() => socketContext.Dispose()))\n            {\n                await socketContext.WriteStream.WriteInt16Async((short)ClientRouterMessage.RequestServer).ConfigureAwait(false);\n                await socketContext.WriteStream.WriteStringAsync(serverUrl).ConfigureAwait(false);\n                await socketContext.WriteStream.FlushAsync().ConfigureAwait(false);\n\n                var result = (ClientRouterMessage)await socketContext.ReadStream.ReadInt16Async().ConfigureAwait(false);\n                if (result != ClientRouterMessage.ServerStarted)\n                {\n                    throw new SimpleSocketException(\"Could not connect to server\");\n                }\n\n                var errorCode = await socketContext.ReadStream.ReadInt32Async().ConfigureAwait(false);\n                if (errorCode != 0)\n                {\n                    var errorMessage = await socketContext.ReadStream.ReadStringAsync().ConfigureAwait(false);\n                    throw new SimpleSocketException(errorMessage);\n                }\n            }\n\n            return socketContext;\n        }\n\n        /// <summary>\n        /// Initiates a connection to the router.\n        /// </summary>\n        /// <returns></returns>\n        private static async Task<SimpleSocket> InitiateConnectionToRouter()","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Engine/Network/RouterClient.cs#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"Router service not running properly or unreachable relay backend; wrong server URL given to the router; network interruption causing a truncated/garbled response 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."],"exampleFix":"// before\nvar conn = await routerClient.RequestServer(\"tcp://myhost:12345\");\n// after\nSimpleSocketException ex = null;\nfor (int i = 0; i < 3; i++)\n{\n    try { var conn = await routerClient.RequestServer(serverUrl); break; }\n    catch (SimpleSocketException e) { ex = e; await Task.Delay(1000 * (i + 1)); }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { conn = await router.RequestServer(serverUrl); }\ncatch (SimpleSocketException e) { /* inspect router health / retry with backoff */ }","preventionTips":["Health-check the router before requesting servers.","Validate the serverUrl format and registration on the router.","Implement retry with exponential backoff for transient failures."],"tags":["network","socket","router","handshake"],"backgroundTag":"connection-refused","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}