Android上的MqttException

时间:2011-02-18 20:17:18

标签: android push-notification mq

我一直在跟踪Dale Lane's blog通过我的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项目连接相同的服务参数。

非常感谢!

1 个答案:

答案 0 :(得分:1)

感谢Dale,我只需要将localhost地址更改为10.0.2.2,休息一切顺利。