Skip to main content

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

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