njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

UUID as client ID #85

Closed marclennox closed 7 years ago

marclennox commented 7 years ago

I understand that MQTT 3.1.1 allows client IDs longer than 23, but this library still restricts them to 23. Any objections to removing this restriction?

njh commented 7 years ago

Hi @marclennox,

If you enable version 3.1.1 mode in the client (client.version = '3.1.1'), then there is no restriction on the Client ID length. See: https://github.com/njh/ruby-mqtt/blob/master/lib/mqtt/packet.rb#L483

However version 3.1.1 specifies "The Server MAY allow ClientId’s that contain more than 23 encoded bytes." - so it is possible that there are MQTT servers that don't.

In terms of the library generating a client id automatically, version 3.1.1 of the protocol specifies that a server may allow an empty client id:

A Server MAY allow a Client to supply a ClientId that has a length of zero bytes, however if it does so the Server MUST treat this as a special case and assign a unique ClientId to that Client.

Which is much better than the client randomly making one up.

Let me know if I am missing something or you have discovered a bug.

nick.

marclennox commented 7 years ago

Thanks @njh, this worked for me!