localhost导致MQTT本地客户端与本地broker无法连接问题
作者:互联网
今天在调试时发现一个localhost问题:
#define EMBER_AF_PLUGIN_TRANSPORT_MQTT_BROKER_ADDRESS "tcp://localhost:1883"
#define EMBER_AF_PLUGIN_TRANSPORT_MQTT_BROKER_ADDRESS_LENGTH (20)
当MQTT客户端设置本地地址为localhost:1883时,无法连接本地broker.
#define EMBER_AF_PLUGIN_TRANSPORT_MQTT_BROKER_ADDRESS "tcp://127.0.0.1:1883"
#define EMBER_AF_PLUGIN_TRANSPORT_MQTT_BROKER_ADDRESS_LENGTH (20)
修改localhost为127.0.0.1后问题解决
这里分析原因:
root@sun8i:/etc# ls
adb_profile etc_complete modules-boot.d rc.d
banner fstab modules.d res
banner.failsafe group mtab resolv.conf
camera.cfg hotplug.d openwrt_release shadow
cedarx.conf init.d openwrt_version shells
config inittab opkg ts.conf
crontabs localtime opkg.conf tslib-env.sh
device_info lost+found passwd uci-defaults
dnsmasq.conf mdev.conf profile wifi
e2fsck.conf mediafile.txt rc.common xr_wifi.conf
root@sun8i:/etc# cd ..
root@sun8i:/# find . -name hosts
root@sun8i:/#
可以看到,嵌入式板子上/etc目录下没有host文件,所以无法解析localhost字符串,这才是问题的原因,大家在遇到类似问题时请多注意域名的解析问题。
标签:本地,EMBER,broker,MQTT,localhost,conf,ADDRESS,sun8i 来源: https://blog.csdn.net/weixin_41472344/article/details/105635822