GithubHelp home page GithubHelp logo

Comments (6)

learn-more avatar learn-more commented on May 26, 2024 1

This is an mqtt feature.
If you want a clean session, connect using the flag MQTT_CONNECT_CLEAN_SESSION, or indeed generate a random name.

from mqtt-c.

LiamBindle avatar LiamBindle commented on May 26, 2024 1

@anselmobattisti this could also be accomplished with an anonymous client ID (which @learn-more is adding) if the broker you're connecting to supports it.

See #51

from mqtt-c.

learn-more avatar learn-more commented on May 26, 2024

There is also the option to connect with an empty client name, but MQTT-C does not support that yet.
I have some code to fix that, and will send in a pull request for that somewhere this week.

from mqtt-c.

LiamBindle avatar LiamBindle commented on May 26, 2024

@anselmobattisti, Thanks for the feature request. I agree with @learn-more though.

The MQTT_CONNECT_CLEAN_SESSION flag should be sufficient. Appending a random string to the client ID that you pass to mqtt_connect() make sense if you have multiple client instances for a single "logical client", but I think that's not something MQTT-C should do itself.

I'm going to close this feature request, but feel free to reopen if I've misinterpreted anything.

from mqtt-c.

anselmobattisti avatar anselmobattisti commented on May 26, 2024

thaks for the answars,

The MQTT nodejs component, for example, appends a random string at the connection name every new connections.

mosquitto | 1570369305: New client connected from 172.19.0.1 as mqttjs_e769b829 (p2, c1, k60).
mosquitto | 1570369833: New client connected from 172.19.0.1 as UVIRW (p2, c0, k400).
mosquitto | 1570369868: New client connected from 172.19.0.1 as mqttjs_3eea51ba (p2, c1, k60).

The second one is the random i generate inside a docer container in C

In my case the client is a process inside a docker container and many of this containers are strated at the same time.

The MQTT_CONNECT_CLEAN_SESSION should be used where?

from mqtt-c.

LiamBindle avatar LiamBindle commented on May 26, 2024

The anonymous client ID functionality added by @learn-more is a clean replacement for what you're doing with the second one. I think that will be merged in the next couple days.

The MQTT_CONNECT_CLEAN_SESSION should be used where?

The MQTT_CONNECT_CLEAN_SESSION flag forces the broker to start the client's session "fresh" (throw out any existing state).

From the MQTT 3.1.1 Spec:

3.1.2.4 Clean Session
...
If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new one. This Session lasts as long as the Network Connection. State data associated with this Session MUST NOT be reused in any subsequent Session [MQTT-3.1.2-6].

I think you probably want to be using this flag. It will cause the broker to terminate the session when the connection closes (otherwise your broker might accumulate open sessions with closed connections).

from mqtt-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.