Skip to main content

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

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)

 

????


Back to the top