Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] MQTT android: connection refused



My code in android service


public void onCreate() {

                         // TODO Auto-generated method stub


            Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

                         try {

                                     Toast.makeText(this, "before try", Toast.LENGTH_LONG).show();

                                     client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2", new MemoryPersistence());


                             //  client = new MqttClient("tcp://localhost:1883", "pahomqttpublish2");

                               Toast.makeText(this, "after creating the mqttclient", Toast.LENGTH_LONG).show();


                               MqttMessage message = new MqttMessage();

                               message.setPayload("A single wessage".getBytes());

                               client.publish("pahodemo/test", message);


                             } catch (MqttException e) {

                               Toast.makeText(this, "went to exception", Toast.LENGTH_LONG).show();





It creates the client but cannot connect to the server.

In logcat:


unable to connect to server (32103) - failed to connect to localhost/ 1883) after 3000ms: isConnected failed: ECONNREFUSED (connection refused)



Back to the top