Comments (6)
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.
@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.
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.
@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.
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.
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)
- Adding contex to callbacks HOT 1
- Insufficient validation of PUBLISH message HOT 2
- Possible undefined behaviour/bad memory access after reconnect HOT 2
- MQTT_ERROR_SEND_BUFFER_IS_FULL due to transient MQTT_ERROR_SOCKET_ERROR
- FPU-Trap when calculating client->typical_response_time
- mqtt_publish return value causes mqtt_error_str when not connected
- mqtt_publish seems to only send QoS 0 HOT 1
- Possible bug in MQTT_CLIENT_TRY_PACK macro
- MQTT-C Security Issue Report (mqtt_unpack_publish_response) HOT 2
- swap use of double variables to float HOT 1
- How to check the client has received a Connack from the Broker after connect() HOT 7
- how to check network connection state in inspector callback
- Signed integer overflow in `mqtt_error_str()` HOT 2
- We cannot pass the context of the program to mqtt publish_callback HOT 2
- Mingw compile error
- Memory alignment in Keil ARM Compiler (thumb instruction set)
- mqtt_connect does not generate a client.error if wrong username and/or password is provided
- Unable to connect openssl_publisher example to HiveMQ HOT 2
- Windows MSYS2 MINGW64: Examples fail with "MQTT_ERROR_SOCKET_ERROR" or "Failed to open socket: : No error"
- MQTT-C endless loop if sendbuffer is too large
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqtt-c.