我一直在关注Dale Lane 的博客,通过我的 Android 项目访问 Mosquitto,但我卡在了第一步。这是日志的相关部分:
02-24 20:43:17.324: WARN/System.err(316): com.ibm.mqtt.MqttException
02-24 20:43:17.534: WARN/System.err(316): at com.ibm.mqtt.MqttBaseClient.doConnect(Unknown Source)
02-24 20:43:17.534: WARN/System.err(316): at com.ibm.mqtt.MqttBaseClient.connect(Unknown Source)
02-24 20:43:17.534: WARN/System.err(316): at com.ibm.mqtt.MqttClient.connect(Unknown Source)
02-24 20:43:17.534: WARN/System.err(316): at com.ibm.mqtt.MqttClient.connect(Unknown Source)
02-24 20:43:17.534: WARN/System.err(316): at com.push.MQTTService.connectToBroker(MQTTService.java:665)
02-24 20:43:17.584: WARN/System.err(316): at com.push.MQTTService.handleStart(MQTTService.java:294)
02-24 20:43:17.584: WARN/System.err(316): at com.push.MQTTService.onStartCommand(MQTTService.java:210)
02-24 20:43:17.594: WARN/System.err(316): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
02-24 20:43:17.594: WARN/System.err(316): at android.app.ActivityThread.access$3600(ActivityThread.java:125)
02-24 20:43:17.594: WARN/System.err(316): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
02-24 20:43:17.594: WARN/System.err(316): at android.os.Handler.dispatchMessage(Handler.java:99)
02-24 20:43:20.107: WARN/System.err(316): at com.ibm.mqtt.MqttBaseClient.doConnect(Unknown Source)
02-24 20:43:20.107: WARN/System.err(316): at com.ibm.mqtt.MqttBaseClient.connect(Unknown Source)
02-24 20:43:20.114: WARN/System.err(316): at com.ibm.mqtt.MqttClient.connect(Unknown Source)
02-24 20:43:20.124: WARN/System.err(316): at com.ibm.mqtt.MqttClient.connect(Unknown Source)
02-24 20:43:20.124: WARN/System.err(316): at com.push.MQTTService.connectToBroker(MQTTService.java:665)
02-24 20:43:20.124: WARN/System.err(316): at com.push.MQTTService.access$6(MQTTService.java:658)
02-24 20:43:20.124: WARN/System.err(316): at com.push.MQTTService$NetworkConnectionIntentReceiver.onReceive(MQTTService.java:883)
02-24 20:43:20.274: WARN/System.err(316): Caused by: java.net.ConnectException: /127.0.0.5:1883 - Connection refused
02-24 20:43:20.304: WARN/System.err(316): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:254)
02-24 20:43:20.344: WARN/System.err(316): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
02-24 20:43:20.344: WARN/System.err(316): at java.net.Socket.connect(Socket.java:1055)
02-24 20:43:20.344: WARN/System.err(316): at com.ibm.mqtt.j2se.MqttJava14NetSocket.<init>(Unknown Source)
02-24 20:43:20.344: WARN/System.err(316): at com.ibm.mqtt.j2se.MqttJavaNetSocket.setConnection(Unknown Source)
02-24 20:43:20.376: WARN/System.err(316): at com.ibm.mqtt.Mqtt.tcpipConnect(Unknown Source)
02-24 20:47:17.677: DEBUG/SntpClient(65): request time failed: java.net.SocketException: Address family not supported by protocol
Dale 代码的“connectToBroker()”方法抛出异常:
mqttClient.connect("_unique_client_id", true, (short) 2000); //tried many permutations
我在与客户端相同的机器上运行 Mosquitto 代理。我可以通过示例中提供的 IA92 客户端发布/订阅代理。我还可以通过具有相同服务参数的简单 java 项目进行连接。
非常感谢 !