更改mqtt服务器的位置为localhost

This commit is contained in:
flykhan 2023-10-26 20:00:47 +08:00
parent bbc326d8ef
commit 769064c24e
3 changed files with 5 additions and 5 deletions

View File

@ -25,8 +25,8 @@ int main(int argc, char const *argv[])
mosquitto_lib_init(); // 初始化(固定格式) mosquitto_lib_init(); // 初始化(固定格式)
struct mosquitto *client = mosquitto_new(NULL, true, NULL); // 创建客户端 struct mosquitto *client = mosquitto_new(NULL, true, NULL); // 创建客户端
mosquitto_connect_callback_set(client, connect_callback); // 设置连接回调函数 mosquitto_connect_callback_set(client, connect_callback); // 设置连接回调函数
// mosquitto_connect(client, "localhost", 1883, 60); // 连接服务器(地址,端口,超时时间) mosquitto_connect(client, "localhost", 1883, 60); // 连接服务器(地址,端口,超时时间)
mosquitto_connect(client, "flykhan.com", 1883, 60); // 连接服务器(地址,端口,超时时间) // mosquitto_connect(client, "flykhan.com", 1883, 60); // 连接服务器(地址,端口,超时时间)
mosquitto_loop_start(client); // 开启客户端线程 mosquitto_loop_start(client); // 开启客户端线程
while (isConnected == 0) while (isConnected == 0)
; // 等待连接成功(当连接成功后isConnected会被置为1然后跳出循环) ; // 等待连接成功(当连接成功后isConnected会被置为1然后跳出循环)

View File

@ -150,8 +150,8 @@ int main(int argc, char const *argv[])
mosquitto_message_callback_set(client, on_message); // 设置接收消息回调函数,用于接收到消息后的处理 mosquitto_message_callback_set(client, on_message); // 设置接收消息回调函数,用于接收到消息后的处理
// 3. 连接mqtt broker // 3. 连接mqtt broker
// int flag = mosquitto_connect(client, "localhost", 1883, 60); int flag = mosquitto_connect(client, "localhost", 1883, 60);
int flag = mosquitto_connect(client, "flykhan.com", 1883, 60*60*24*30); // 连接服务器(地址,端口,超时时间) : 超时时间为一个月 //int flag = mosquitto_connect(client, "flykhan.com", 1883, 60*60*24*30); // 连接服务器(地址,端口,超时时间) : 超时时间为一个月
if (flag == MOSQ_ERR_SUCCESS) if (flag == MOSQ_ERR_SUCCESS)
{ {
printf("-----连接MQTT 服务器成功!-----\n"); printf("-----连接MQTT 服务器成功!-----\n");

Binary file not shown.