{"record":{"id":"9647a15d1e2d504f","repo":"ratchetphp/Ratchet","slug":"invalid-wamp-message-type","errorCode":null,"errorMessage":"Invalid WAMP message type","messagePattern":"Invalid WAMP message type","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Ratchet/Wamp/ServerProtocol.php","lineNumber":141,"sourceCode":"            break;\n\n            case static::MSG_PUBLISH:\n                $exclude  = (array_key_exists(3, $json) ? $json[3] : null);\n                if (!is_array($exclude)) {\n                    if (true === (bool)$exclude) {\n                        $exclude = [$from->WAMP->sessionId];\n                    } else {\n                        $exclude = [];\n                    }\n                }\n\n                $eligible = (array_key_exists(4, $json) ? $json[4] : []);\n\n                $this->_decorating->onPublish($from, $from->getUri($json[1]), $json[2], $exclude, $eligible);\n            break;\n\n            default:\n                throw new Exception('Invalid WAMP message type');\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function onClose(ConnectionInterface $conn) {\n        $decor = $this->connections[$conn];\n        $this->connections->offsetUnset($conn);\n\n        $this->_decorating->onClose($decor);\n    }\n\n    /**\n     * {@inheritdoc}\n     */\n    public function onError(ConnectionInterface $conn, \\Exception $e) {\n        return $this->_decorating->onError($this->connections[$conn], $e);","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/ratchetphp/Ratchet/blob/e621c6c40bf684bbbb877102416ad5303d05a9cc/src/Ratchet/Wamp/ServerProtocol.php#L123-L159","documentation":"This is the `default` branch of the message-type switch in ServerProtocol::onMessage: any frame whose element 0 is not one of WAMP's client-to-server types (1 PREFIX, 2 CALL, 5 SUBSCRIBE, 6 UNSUBSCRIBE, 7 PUBLISH) reaches it. Server-only types (WELCOME=0, CALL RESULT=3, CALL ERROR=4, EVENT=8) and unknown type codes fall through here. The library throws because it cannot dispatch a message type it never expects to receive from a client.","triggerScenarios":"A client sends [0, ...] (WELCOME), [3, ...], [4, ...], [8, ...] — messages that are server-to-client only — or a completely unknown type code like [99, \"x\"], or an empty array [] where $json[0] is undefined.","commonSituations":"A developer echoing back or relaying server frames into the same socket; test scripts replaying captured server messages; clients speaking WAMP v2 (whose type codes like SUBSCRIBE=32, PUBLISH=16 differ) so codes land on undefined switch values; buggy message routing between connections.","solutions":["Verify the client only sends client-to-server WAMP v1 types: 1 (PREFIX), 2 (CALL), 5 (SUBSCRIBE), 6 (UNSUBSCRIBE), 7 (PUBLISH).","Check for WAMP v2 type codes (e.g. 16 PUBLISH, 32 SUBSCRIBE from newer autobahn clients) — Ratchet implements WAMP v1; use a v1-compatible client or a WAMP v2 router.","Log $json[0] in onError when this exception surfaces to identify the offending type and client.","Catch \\Ratchet\\Wamp\\Exception in your component's onError and close the connection instead of letting it poison the loop."],"exampleFix":"// before (client)\nws.send(JSON.stringify([16, {}, 'kittens', 'hello'])); // WAMP v2 PUBLISH\n// after (WAMP v1)\nws.send(JSON.stringify([7, 'kittens', 'hello']));","handlingStrategy":"validation","validationCode":"$frame = json_decode($msg, true);\n$validClientTypes = [1, 2, 5, 6, 7]; // PREFIX, CALL, SUBSCRIBE, UNSUBSCRIBE, PUBLISH\nif (!isset($frame[0]) || !in_array($frame[0], $validClientTypes, true)) {\n    // reject: not a valid client-to-server WAMP v1 message type\n}","typeGuard":"function isClientToServerWampType($type): bool {\n    return in_array($type, [1, 2, 5, 6, 7], true);\n}","tryCatchPattern":"try {\n    $server->onMessage($conn, $msg);\n} catch (\\Ratchet\\Wamp\\Exception $e) {\n    error_log(\"Unknown WAMP type from {$conn->remoteAddress}: \" . $msg);\n    $conn->close();\n}","preventionTips":["Only send client-to-server types (1, 2, 5, 6, 7) to a Ratchet WAMP server.","Never echo or relay server-to-client frames (0, 3, 4, 8) back into the socket.","Confirm the client speaks WAMP v1; v2 type codes (16/32/...) all land in this default branch.","Capture $json[0] in error logs to diagnose mismatched protocol versions."],"tags":["websocket","wamp","message-type","protocol"],"backgroundTag":"invalid-enum-value","analyzedSha":"e621c6c40bf684bbbb877102416ad5303d05a9cc","analyzedAt":"2026-09-16T00:13:27.878Z","contentChangedAt":"2026-09-16T00:13:27.878Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}