#include <nng/nng.h>
#include <nng/mqtt/mqtt_client.h>
int nng_mqtt_client_open(nng_socket *sock);
The nng_mqtt_client_open()
Create a MQTT client dose nit connect it.
Note that MQTT sockets can be connected to at most a single server.
Must create MQTT CONNECT message for dialer by message functions: nng_mqtt_msg_alloc(), nng_mqtt_msg_set_connect()
client demo snippet
if ((rv = nng_mqtt_client_open(&sock)) != 0) {
fatal("nng_socket", rv);
}
nng_msg *msg;
nng_mqtt_msg_alloc(&msg, 0);
nng_mqtt_msg_set_packet_type(msg, NNG_MQTT_CONNECT);
if ((rv = nng_dialer_create(&dialer, sock, url)) != 0) {
fatal("nng_dialer_create", rv);
}
nng_dialer_set_ptr(dialer, NNG_OPT_MQTT_CONNMSG, msg);
nng_dialer_start(dialer, NNG_FLAG_NONBLOCK);