hivemq / hivemq-mqtt-web-client

A websockets based MQTT Client for your browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Websocket client incorrectly assumes websocket frames and mqtt frames are aligned

halfgaar opened this issue · comments

The specs say:

MQTT-6.0.0-2: A single WebSocket data frame can contain multiple or partial MQTT Control Packets. The receiver MUST NOT assume that MQTT Control Packets are aligned on WebSocket frame boundaries.

The HiveMQ websocket client does assume that. You can see that a message is split up here looking at raw WS frames:

HiveMQ_WS_Frames

The '06 ' is just an ASCII print of the MQTT raw data. The string heartbeat is the topic, and Heartbeat at... the payload.

The server closes the connection:

HiveMQ_WS_console_output

The websocket frames show that the data continues with " CEST 2021". So, the first char is a space, in other words: 0b00100000. In MQTT, the first bytes of a CONNACK is also 0b00100000, followed by the response code. So, hence the error code 'bad connack', because it thinks it's a MQTT connack packet, because it assumes websocket frame == mqtt frame.

The client needs to do its own frame bookkeeping, and not rely on the browser only delivering complete frames.