Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 1.82 KB

nng_mqtt_client_open.3.adoc

File metadata and controls

70 lines (52 loc) · 1.82 KB

nng_mqtt_client_open(3)

NAME

nng_mqtt_client_open - open mqtt socket client

SYNOPSIS

#include <nng/nng.h>
#include <nng/mqtt/mqtt_client.h>

int nng_mqtt_client_open(nng_socket *sock);

DESCRIPTION

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);

RETURN VALUES

This function returns 0 on success, and non-zero otherwise.

ERRORS

NNG_ENOTSUP

MQTT not supported.