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, 

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

Back to the top