Skip to main content

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

Hi Rhys,


Mosquitto broker is running on my laptop.

When I try with a simple java project it works fine and I can publish on the broker.


But with android I don’t know why connection gets refused…?

Is it wrong to use tcp://localhost:1883 in Android as broker address?





From: paho-dev-bounces@xxxxxxxxxxx [mailto:paho-dev-bounces@xxxxxxxxxxx] On Behalf Of Rhys Short
Sent: den 5 februari 2014 15:15
To: General development discussions for paho project
Subject: Re: [paho-dev] MQTT android: connection refused




On android local host is the phone or emulator, you need to give it an ip or host name to connect to





Sent from my iPhone

On 5 Feb 2014, at 14:05, "Golnaz Makhtoumi" <Golnaz.Makhtoumi@xxxxxx> wrote:



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)



paho-dev mailing list

Back to the top