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 Gonaz, 

It is valid, but because android emulator is the whole operating system running in a emulator, it treats local host as itself so you need to use the ip address  your laptop has to connect to the broker. 

Rhys

Sent from my iPhone

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

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?

 

//Golnaz

 

 

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

 

Hi, 

 

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

 

 

Rhys

 



Sent from my iPhone


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

Hi,

 

My code in android service

 

public void onCreate() {

                         // TODO Auto-generated method stub

                         super.onCreate();

            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();

                               client.connect();

                               MqttMessage message = new MqttMessage();

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

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

                              client.disconnect();

                             } catch (MqttException e) {

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

                               e.printStackTrace();

                              

                             }

 

It creates the client but cannot connect to the server.

In logcat:

 

unable to connect to server (32103) - java.net.connectException: failed to connect to localhost/127.0.0.1(port 1883) after 3000ms: isConnected failed: ECONNREFUSED (connection refused)

 

????

_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev

_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev

Back to the top