Explaining the flow of the program

100 views
Skip to first unread message

prem singhania

unread,
Sep 22, 2015, 2:49:45 AM9/22/15
to MQTT
Hello,
     I have attached a small mqtt program here which uses mosquitto client library and a c apollo broker, the program works but I was interested in knowing the flow in which it is executed. I would be thankful if someone could tell me if its a multithreaded program or single threaded.
#include<stdio.h>
#include<stdlib.h>
#include<mosquitto.h>
#include<string.h>

void on_publish(struct mosquitto *mosq, void *userdata, int mid)
{
    printf("Inside publish");

   mosquitto_disconnect(mosq);
}

int main(int argc, char *argv[])
{
    struct mosquitto *mosq;
    int err,err1;
    char *data = "lets wait";
    char *retain_flag="true";
    char *clean_session = "false";
    char *address = "localhost";
    char *port = "61613";
    int port1 = atoi(port);
 

    mosq = mosquitto_new("1234",clean_session,NULL);

    mosquitto_publish_callback_set(mosq, on_publish);
   

   // mosquitto_username_pw_set(mosq,"admin","password");

    err1= mosquitto_connect(mosq,address,port1,60);
    printf("%s",mosquitto_strerror(err1));

    err=mosquitto_publish(mosq, NULL, "subject",strlen(data),data,1,retain_flag);
    printf("Error: %s",mosquitto_strerror(err));
if(err > 0)
{
        printf("Error: %s",mosquitto_strerror(err));
}
    mosquitto_loop_forever(mosq, -1, 1);  // this calls mosquitto_loop() in a loop, it will exit once the client disconnects cleanly

    printf("outside the loop");
    return 0;

}



Thanks in advance


Jan-Piet Mens

unread,
Sep 22, 2015, 3:19:16 AM9/22/15
to mq...@googlegroups.com
> char *clean_session = "false";
> char *port = "61613";
> int port1 = atoi(port);

> mosq = mosquitto_new("1234",clean_session,NULL);

OMG.

> the program works

I doubt that.

-JP

prem singhania

unread,
Sep 22, 2015, 3:39:02 AM9/22/15
to MQTT
Shouldn't it work??Why whats wrong with it?

Nicholas O'Leary

unread,
Sep 22, 2015, 4:08:59 AM9/22/15
to mq...@googlegroups.com
Hi,

this mailing list is about the MQTT protocol, not individual implementations. I suggest you take this to the mosquitto mailing list.

Nick

--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages