zevv / nmqtt

Native Nim MQTT client library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Packet max size: 128 - increase?

ThomasTJdev opened this issue · comments

When trying to send a large payload, the send() is going through the await send(), but nothing is received on the MQTT broker. Furthermore this will also block all the next messages, pings, etc.
I think I have located it to be the sizing due to uint8, so when reaching 128 - it breaks.

I have digged into hdr and pkt structure in send(), but everything seems ok. Any suggestions?

Please try sending a payload (topic + msg) on specific 128 and more.

Not sure if this is related, but the "remaining length" header is not completely implemented, check section "2.2.3 Remaining Length" of http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html: at this time everything bigger then 16K will mess up because send() lacks the two missing cases for encoding bigger sizes.

Thanks @zevv . Currently the problem is from 128->16383, where the message is not sent at all. The last 2 cases must be step2 :) .

The package is going through

elif len <= 16383:
    hdr.add ((len /% 128) or 0x80).uint8
    hdr.add (len mod 128).uint8

but is not sent.

I've done some digging - but I have currently lost against the MQTT-protocol...

Working package size

#Pkg len = 127:
@[52, 127]
# is sent

#Pkg len = 128:
@[52, 129, 0]
# fails => Exception message: Bad file descriptor

#Pkg len = 129:
@[52, 129, 1]
# is sent

#Pkg len = 130:
@[52, 129, 2]
# is *not* sent

Checking the package with Wireshark:

When using a package lower than 127 the Protocol is MQTT and the message is sent as a Publish Message. While using a package with higher length, e.g. 143, the data is sent a Protocol TCP.

Pkg.len = 127:

Frame: eth:ethertype:ip:tcp:mqtt
image

Pkg.len = 143

Frame: eth:ethertype:ip:tcp
image

Dooh.. just as you said, follow 2.2.3.. Thank you @zevv!