Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Help! Paho MQTT Android Application

Hi All,

 

I want to stablish a connection to local broker (Mosquitto) by MQTT.

The simple java project is working and I can publish a message.

 

But now when I want to use the same concept in Android project, it only goes to exception.

Here is the main code inside the MQTTService.java (which is a service)

 

@Override

            public void onCreate() {

                         // TODO Auto-generated method stub

                         super.onCreate();

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

                         try {

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

                               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 seems like it does go into try but cannot create instance of MqttClient and then throws exception.

 

In logcat under syste,.err tag I get MqttException(0) at org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:76)

And so on..

 

What am I doing wrong?

 

Thanks in advance

 


Back to the top