目录
org.eclipse.paho.client.mqttv3.MqttException: 无法连接至服务器
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:80) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:724) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at java.lang.Thread.run(Thread.java:750) ~[na:1.8.0_333]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_333]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:81) ~[na:1.8.0_333]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476) ~[na:1.8.0_333]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218) ~[na:1.8.0_333]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200) ~[na:1.8.0_333]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:162) ~[na:1.8.0_333]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394) ~[na:1.8.0_333]
at java.net.Socket.connect(Socket.java:606) ~[na:1.8.0_333]
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:74) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
... 2 common frames omitted
我报这个错的原因是MQTT的配置文件没有设置允许远程连接导致的,如果你也是因为配置文件导致的Connection refused: connect错误,那么请往下看:
设置允许所有ip连接
设置允许远程连接
假如你没有添加上面这个配置,那么会报下面这个错误:
org.eclipse.paho.client.mqttv3.MqttSecurityException: 无权连接
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:1053) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:151) ~[org.eclipse.paho.client.mqttv3-1.2.5.jar:na]
at java.lang.Thread.run(Thread.java:750) ~[na:1.8.0_333]
只配置了listener 1883 0.0.0.0而不配置allow_anonymous true的话会报无权连接的问题!
👍点赞,你的认可是我创作的动力 !
🌟收藏,你的青睐是我努力的方向!
✏️评论,你的意见是我进步的财富!