Client sample code
void on_message(struct mosquitto *m, void *user_data, const struct mosquitto_message *msg) {
fprintf(stderr, "Message from %s is %s\n", msg->topic, (char*)msg->payload);
}
int main(int argc, char **argv) {
struct mosquitto *client; int ret;
mosquitto_lib_init();
client = mosquitto_new("client-id", true, NULL);
ret = mosquitto_connect(client, "127.0.0.1", 1883, 60);
ret = mosquitto_subscribe(client, NULL, "my/topic/to/subscribe", 0);
mosquitto_message_callback_set(client, on_message);
while (MOSQ_ERR_SUCCESS == mosquitto_loop(client, -1, 1));
}