Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Long timeouts to real sites with no MQTT

Hi Steven,

The connection timeout is there for when a socket is successfully
connected but the other end doesn't respond to the initial MQTT
connect packet exchange in a timely fashion.

I've run your code a few times and it times out for my after roughly
5-6 seconds:

nol@noltop:/tmp/Mqttv3ClientOut/ship$ java -classpath
org.eclipse.paho.client.mqttv3.jar:. SuperSimple
(00:05.624)Exception: Unable to connect to server

I get exactly the same results when I change the code to remove the
MqttClient altogether and just try to connect a raw socket (code
attached). Could you give that a go and see what you get?

I also get the same result when I simply try telnet'ing to that server/port:

nol@noltop:~$ time telnet some.company.net 1883
Trying 82.98.86.161...
telnet: Unable to connect to remote host: Connection refused

real 0m6.121s
user 0m0.000s
sys 0m0.000s



What operating system are you running this on? I suspect there is an
underlying socket level timeout coming into play here.

Cheers,
Nick

On 26 February 2013 03:29, Steven Luke <stevejluke@xxxxxxxxx> wrote:
> When I make a connection to a valid looking Host Address, but which does not
> have an MQTT server running I get a seriously long timeout (I think it may
> actually never end in some cases).  I tried setting the Connection Timeout
> to 20, or 5, or anything, but it doesn't work.  Anything I can try to make
> the client realize the connection is no-good earlier?  Alternatively is
> there something I can manually do in another thread to make the connection
> stop trying?
>
> This is a big issue for me, because the setting will be user-configurable
> and if it takes this long to fail it means a negative and very visible user
> experience.  I would like it to fail in 30 seconds or less so I can prompt
> for them to modify the address without making them wait for minutes to set
> up.
>
> Thanks,
> Steve
>
> Here is sample code which shows the problem.  In plain desktop Java it takes
> a consistent 1 minute, 3 seconds to fail.  I use the same code on android,
> and on WiFi it takes about the same time (a little over a minute), but on
> 3G/4G it takes 2+ minutes, and I timed one (google.com) at >10 minutes
> before killing it.
>
> public class SuperSimple
> {
>     public static final String timeDiffFormat = "%1$tM:%1$tS.%1$tL";
>     private static MqttClient client;
>
>     public static void main(String... args)
>     {
>         final long startTime = System.currentTimeMillis();
>         try
>         {
>             client = new MqttClient("tcp://some.company.net:1883",
> "this_should_fail_fast");
>
>             MqttConnectOptions mOptions = new MqttConnectOptions();
>             mOptions.setKeepAliveInterval(20);
>             mOptions.setConnectionTimeout(20);
>             client.connect(mOptions);
>
>         }
>         catch (MqttException mEx)
>         {
>             long errorTime = System.currentTimeMillis();
>             Date difference = new Date(errorTime - startTime);
>             String time = String.format(Locale.US, timeDiffFormat,
> difference);
>             String message = mEx.getMessage();
>             System.out.printf("(%s)Exception: %s%n", time, message);
>         }
>
>         try
>         {
>             client.disconnect();
>         }
>         catch (MqttException e)
>         {
>             //This always happens: already disconnected.
>         }
>     }
> }
>
>
> _______________________________________________
> paho-dev mailing list
> paho-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/paho-dev
>

Attachment: SocketTest.java
Description: Binary data


Back to the top