* Important note
*
* The following functions that deal with network operations will return
* MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has
* taken place. An attempt will be made to write the network data, but if the
* socket is not available for writing at that time then the packet will not be
* sent. To ensure the packet is sent, call mosquitto_loop() (which must also
* be called to process incoming network data).
* This is especially important when disconnecting a client that has a will. If
* the broker does not receive the DISCONNECT command, it will assume that the
* client has disconnected unexpectedly and send the will.
*
* mosquitto_connect()
* mosquitto_disconnect()
* mosquitto_subscribe()
* mosquitto_unsubscribe()
* mosquitto_publish()
You haven't called one of the mosquitto_loop*() functions, so you will
never receive a CONNACK. You've also not called mosquitto_lib_init().
If you want the publish to happen after a successful connection, put
it in the on_connect() callback. If you want to disconnect after a
successful publish, but that in the on_publish() callback and use a
while loop to call mosquitto_loop() (or just use
mosquitto_loop_forever()).
On Tue, Dec 17, 2013 at 11:05 AM, Yun Wu <wuyun1984_1984@163.com> wrote:
> ** Description changed:
>
> It seems that blocking mode is not really supported.
>
> Topology: publisher -- broker -- subscriber
> Publisher simply publish a message then exit.
> Subscriber sometimes can receive message published by publisher, but sometimes not.
>
> The root cause is, libmosquitto does not really support blocking mode.
> mosquitto_connect_bind --> _mosquitto_reconnect --> _mosquitto_send_connect
> That means mosquitto_connect_bind() does not wait until CONNACK arrives.
>
> Logs can prove that:
> ----
> 1387273535: New connection from 172.18.111.243 on port 1883.
> 1387273535: New client connected from 172.18.111.243 as TestClientId (c1, k3600).
> 1387273535: Sending CONNACK to TestClientId (0)
> 1387273535: Socket error on client TestClientId, disconnecting.
> ----
> We can see:
> 1) Broker has not received PUBLISH message from publisher.
> 2) Broker has not received DISCONNECT message from publisher.
>
> All because blocking mode is not really supported.
>
> - In blocking mode,
> + In blocking mode,
> mosquitto_connect_bind should wait until CONNACK arrives;
> If QoS not 0, mosquitto_publish should wait unit ...
> mosquitto_subscribe should wait unit ...
> ...
> +
> +
> +
> + Here is code of the publisher:
> +
> + #include <errno.h>
> + #include <stdio.h>
> + #include <stdlib.h>
> + #include <string.h>
> + #include <unistd.h>
> + #include "mosquitto.h"
> +
> + #define dbg(fmt, args...) \
> + printf("%s(%u): "fmt"\n", __FUNCTION__, __LINE__, ##args)
> +
> + int main(int argc, char *argv[])
> + {
> + struct mosquitto *mosq = NULL;
> + int rv;
> + const char topic[] = "TestTopic";
> + const char buf[] = "Hello, world";
> +
> + if (MOSQ_ERR_SUCCESS != mosquitto_lib_init()) {
> + return -1;
> + }
> +
> + if (NULL == (mosq = mosquitto_new("TestClientId", 1, NULL))) {
> + dbg("mosquitto_new() failed");
> + rv = -1;
> + goto quit;
> + }
> +
> + rv = mosquitto_connect_bind(mosq, "172.18.111.245", 1883, 3600, "172.18.111.243");
> + if (MOSQ_ERR_SUCCESS != rv) {
> + dbg("mosquitto_connect_bind() failed: %s", mosquitto_strerror(rv));
> + if (MOSQ_ERR_ERRNO == rv) {
> + dbg("errno = %d: %s", errno, strerror(errno));
> + }
> + rv = -1;
> + goto quit;
> + }
> +
> + if (MOSQ_ERR_SUCCESS != mosquitto_publish(mosq, NULL, topic, sizeof(buf), buf, 0, 0)) {
> + dbg("mosquitto_publish to %s failed", topic);
> + rv = -1;
> + goto quit;
> + }
> +
> + quit:
> + if (NULL != mosq) {
> + mosquitto_disconnect(mosq);
> + mosquitto_destroy(mosq);
> + }
> + mosquitto_lib_cleanup();
> + return rv;
> + }
>
> --
> You received this bug notification because you are subscribed to
> mosquitto.
> https://bugs.launchpad.net/bugs/1261683
>
> Title:
> Blocking mode is not really supported
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/mosquitto/+bug/1261683/+subscriptions
The documentation says:
* Important note disconnect( ) subscribe( ) unsubscribe( )
*
* The following functions that deal with network operations will return
* MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has
* taken place. An attempt will be made to write the network data, but if the
* socket is not available for writing at that time then the packet will not be
* sent. To ensure the packet is sent, call mosquitto_loop() (which must also
* be called to process incoming network data).
* This is especially important when disconnecting a client that has a will. If
* the broker does not receive the DISCONNECT command, it will assume that the
* client has disconnected unexpectedly and send the will.
*
* mosquitto_connect()
* mosquitto_
* mosquitto_
* mosquitto_
* mosquitto_publish()
You haven't called one of the mosquitto_loop*() functions, so you will lib_init( ).
never receive a CONNACK. You've also not called mosquitto_
If you want the publish to happen after a successful connection, put loop_forever( )).
it in the on_connect() callback. If you want to disconnect after a
successful publish, but that in the on_publish() callback and use a
while loop to call mosquitto_loop() (or just use
mosquitto_
On Tue, Dec 17, 2013 at 11:05 AM, Yun Wu <wuyun1984_ 1984@163. com> wrote: connect_ bind --> _mosquitto_ reconnect --> _mosquitto_ send_connect connect_ bind() does not wait until CONNACK arrives. connect_ bind should wait until CONNACK arrives; lib_init( )) { new("TestClient Id", 1, NULL))) { new() failed"); connect_ bind(mosq, "172.18.111.245", 1883, 3600, "172.18.111.243"); connect_ bind() failed: %s", mosquitto_ strerror( rv)); publish( mosq, NULL, topic, sizeof(buf), buf, 0, 0)) { publish to %s failed", topic); disconnect( mosq); destroy( mosq); lib_cleanup( ); /bugs.launchpad .net/bugs/ 1261683 /bugs.launchpad .net/mosquitto/ +bug/1261683/ +subscriptions
> ** Description changed:
>
> It seems that blocking mode is not really supported.
>
> Topology: publisher -- broker -- subscriber
> Publisher simply publish a message then exit.
> Subscriber sometimes can receive message published by publisher, but sometimes not.
>
> The root cause is, libmosquitto does not really support blocking mode.
> mosquitto_
> That means mosquitto_
>
> Logs can prove that:
> ----
> 1387273535: New connection from 172.18.111.243 on port 1883.
> 1387273535: New client connected from 172.18.111.243 as TestClientId (c1, k3600).
> 1387273535: Sending CONNACK to TestClientId (0)
> 1387273535: Socket error on client TestClientId, disconnecting.
> ----
> We can see:
> 1) Broker has not received PUBLISH message from publisher.
> 2) Broker has not received DISCONNECT message from publisher.
>
> All because blocking mode is not really supported.
>
> - In blocking mode,
> + In blocking mode,
> mosquitto_
> If QoS not 0, mosquitto_publish should wait unit ...
> mosquitto_subscribe should wait unit ...
> ...
> +
> +
> +
> + Here is code of the publisher:
> +
> + #include <errno.h>
> + #include <stdio.h>
> + #include <stdlib.h>
> + #include <string.h>
> + #include <unistd.h>
> + #include "mosquitto.h"
> +
> + #define dbg(fmt, args...) \
> + printf("%s(%u): "fmt"\n", __FUNCTION__, __LINE__, ##args)
> +
> + int main(int argc, char *argv[])
> + {
> + struct mosquitto *mosq = NULL;
> + int rv;
> + const char topic[] = "TestTopic";
> + const char buf[] = "Hello, world";
> +
> + if (MOSQ_ERR_SUCCESS != mosquitto_
> + return -1;
> + }
> +
> + if (NULL == (mosq = mosquitto_
> + dbg("mosquitto_
> + rv = -1;
> + goto quit;
> + }
> +
> + rv = mosquitto_
> + if (MOSQ_ERR_SUCCESS != rv) {
> + dbg("mosquitto_
> + if (MOSQ_ERR_ERRNO == rv) {
> + dbg("errno = %d: %s", errno, strerror(errno));
> + }
> + rv = -1;
> + goto quit;
> + }
> +
> + if (MOSQ_ERR_SUCCESS != mosquitto_
> + dbg("mosquitto_
> + rv = -1;
> + goto quit;
> + }
> +
> + quit:
> + if (NULL != mosq) {
> + mosquitto_
> + mosquitto_
> + }
> + mosquitto_
> + return rv;
> + }
>
> --
> You received this bug notification because you are subscribed to
> mosquitto.
> https:/
>
> Title:
> Blocking mode is not really supported
>
> To manage notifications about this bug go to:
> https:/