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