diff --git a/backend/scripts/testWebSocket.js b/backend/scripts/testWebSocket.js index 2481551..13d2caf 100644 --- a/backend/scripts/testWebSocket.js +++ b/backend/scripts/testWebSocket.js @@ -33,12 +33,14 @@ const pollingReq = http.get(pollingUrl, (res) => { console.log(` Response: ${data.substring(0, 200)}...`); // Versuche Session-ID zu extrahieren + let sessionId = null; try { const jsonMatch = data.match(/\{.*\}/); if (jsonMatch) { const json = JSON.parse(jsonMatch[0]); if (json.sid) { - console.log(` Session ID: ${json.sid}`); + sessionId = json.sid; + console.log(` Session ID: ${sessionId}`); } } } catch (e) { @@ -47,7 +49,7 @@ const pollingReq = http.get(pollingUrl, (res) => { // Test 2: WebSocket-Upgrade console.log('\n2️⃣ Teste WebSocket-Upgrade...'); - testWebSocketUpgrade(host, port); + testWebSocketUpgrade(host, port, sessionId); } else { console.error(` ❌ HTTP-Polling fehlgeschlagen: Status ${res.statusCode}`); process.exit(1); @@ -71,14 +73,17 @@ pollingReq.setTimeout(5000, () => { process.exit(1); }); -function testWebSocketUpgrade(host, port) { +function testWebSocketUpgrade(host, port, sessionId) { // WebSocket-Upgrade-Request const wsKey = Buffer.from(Math.random().toString()).toString('base64').substring(0, 16); + const path = sessionId + ? `/socket.io/?EIO=4&transport=websocket&sid=${sessionId}` + : '/socket.io/?EIO=4&transport=websocket'; const options = { hostname: host, port: port, - path: '/socket.io/?EIO=4&transport=websocket', + path: path, method: 'GET', headers: { 'Upgrade': 'websocket', @@ -100,8 +105,22 @@ function testWebSocketUpgrade(host, port) { } else { console.log(` ⚠️ WebSocket-Upgrade: Status ${res.statusCode} (erwartet: 101)`); console.log(` → Server antwortet, aber Upgrade nicht erfolgreich`); - console.log(` → Möglicherweise wird nur HTTP-Polling unterstützt`); - process.exit(0); + + // Lese Response-Body für weitere Informationen + let body = ''; + res.on('data', (chunk) => { + body += chunk; + }); + res.on('end', () => { + if (body) { + console.log(` Response Body: ${body.substring(0, 200)}`); + } + if (res.statusCode === 400) { + console.log(` → Socket.IO lehnt den Request ab (Bad Request)`); + console.log(` → Möglicherweise fehlt die Session-ID oder sie ist ungültig`); + } + process.exit(0); + }); } });