Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] help socket timeout exception mqtt android

Yes I have that permission.

 

Odd enough I tried my code on emulator (for first time) (I was using real device before) and it worked!!

Anybody knows how to make it work on real android device?!!!

 

//Golnaz

 

From: paho-dev-bounces@xxxxxxxxxxx [mailto:paho-dev-bounces@xxxxxxxxxxx] On Behalf Of Benjamin Cabé
Sent: den 5 februari 2014 19:07
To: General development discussions for paho project
Subject: Re: [paho-dev] help socket timeout exception mqtt android

 

I am sorry if this sounds like a stupid question but did you put the INTERNET permission in your Manifest?

Le 5 févr. 2014 16:50, Golnaz Makhtoumi <Golnaz.Makhtoumi@xxxxxx> a écrit :

What Am I doing wrong?

Im trying to connect to a mosquito broker on my laptop via an android application.  I can ping between two devices so they are connected under same network. There is no firewall on my laptop.

 

When I run the app and press start button (which starts the mqtt service) after 5 or 6 seconds of showing pressed button, I get:

MqttException (0) – java.net.SocketTimeoutException: failed to connect to / my laptops Ip address (port 1883) after 3000ms

 

@Override

            public int onStartCommand(Intent intent, int flags, int startId) {

                         // 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://here I put my laptop’s IP address:1883", "pahomqttpublish2", new MemoryPersistence());

                         //          client = new MqttClient("http://test.mosquitto.org/", "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();

                              

                             }

                                     return super.onStartCommand(intent, flags, startId);

            }

 

 

What am I doing wrong?


Back to the top