File: multiple.c

package info (click to toggle)
mosquitto 2.0.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,556 kB
  • sloc: ansic: 51,107; python: 15,095; xml: 7,187; makefile: 1,819; cpp: 1,541; sh: 305; perl: 70
file content (39 lines) | stat: -rw-r--r-- 629 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include <stdio.h>
#include "mosquitto.h"

#define COUNT 3

int main(int argc, char *argv[])
{
	int rc;
	int i;
	struct mosquitto_message *msg;

	mosquitto_lib_init();

	rc = mosquitto_subscribe_simple(
			&msg, COUNT, true,
			"irc/#", 0,
			"test.mosquitto.org", 1883,
			NULL, 60, true,
			NULL, NULL,
			NULL, NULL);

	if(rc){
		printf("Error: %s\n", mosquitto_strerror(rc));
		mosquitto_lib_cleanup();
		return rc;
	}

	for(i=0; i<COUNT; i++){
		printf("%s %s\n", msg[i].topic, (char *)msg[i].payload);
		mosquitto_message_free_contents(&msg[i]);
	}
	free(msg);

	mosquitto_lib_cleanup();

	return 0;
}