1.初始化mosquitto的库环境 mosquitto_lib_init(); 2.创建mosquitto的服务端 创建服务端句柄 struct mosquitto* client = mosquitto_new(NULL, true, NULL); 3.回调函数 mosquitto_connect_callback_set(client, connect_callback); mosquitto_connect(client, "10.12.156.19", 1883, 60); mosquitto_loop_start(client); 4.发布消息 mosquitto_publish(client, &msg_id, topic, strlen(msg), msg, 1, true);