Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.connect() takes too long if server is unavailable... #1420

Closed
syalujjwal opened this issue Jan 13, 2016 · 19 comments
Closed

client.connect() takes too long if server is unavailable... #1420

syalujjwal opened this issue Jan 13, 2016 · 19 comments

Comments

@syalujjwal
Copy link

syalujjwal commented Jan 13, 2016

In case the server is unavailable, the client.connect() takes too long to return false and come out of the block. This takes 1.5 secs approx. which is too long for my project. Is there a way to solve this problem? Can there be a timeout set in case the client cannot connect within N milli secs?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@syalujjwal syalujjwal changed the title client.connect() takes too long of server is unavailable... client.connect() takes too long if server is unavailable... Jan 15, 2016
@ghost
Copy link

ghost commented Jan 18, 2016

If have got a similar problem. Sometime the Client.connect() of a WIFISecureClient (Release 2.0.0) takes too long to return and causes a WDT reset.

@syalujjwal
Copy link
Author

Hi...any solution for this?

@syalujjwal
Copy link
Author

Hi...still waiting. Please help!!!

@marvinroger
Copy link
Contributor

connect() takes 5 seconds for me, but no WDT reset.

@battuashwik
Copy link

Any update on this. This is becoming a blocker for applications that need to do other jobs when not connected to the server, something like saving state to eeprom.

@igrr
Copy link
Member

igrr commented May 14, 2016

Please quantify "too long". Current behavior is to wait until either "connected" or "connection refused", but not more than 5 seconds. I can change this to the same timeout which is set using client.setTimeout, will this help?

@syalujjwal
Copy link
Author

This should help. I mean any feature that allows the coder to manually set
number seconds to "wait for client or move on" is necessary in many cases.

Please let up know what can be done for this. It's required urgently as
some finished products are facing this issue.

Thanks
On May 14, 2016 8:59 AM, "Ivan Grokhotkov" notifications@github.com wrote:

Please quantify "too long". Current behavior is to wait until either
"connected" or "connection refused", but not more than 5 seconds. I can
change this to the same timeout which is set using client.setTimeout, will
this help?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#1420 (comment)

@battuashwik
Copy link

battuashwik commented May 14, 2016

@igrr, Thanks for reply. That would help a bit but a better way would be to make it asynchronous and let the user monitor a status variable to check if the connection is successful. This way the code is non blocking and use cases where there are other tasks to perform while waiting for the connection can also be done.

Ex.

void loop() {
if (CLIENT_STATUS == "WAITING") {
 // meanwhile can do other jobs also
} else if (CLIENT_STATUS ==  "CONNECTED"){
 // do watever needs to be done after connection
} else {
 client.connect(IP_ADDRESS, MASTER_PORT);
}
}

@igrr
Copy link
Member

igrr commented May 14, 2016

@battuashwik If you need asynchronous operation, then you should probably use ESPAsyncTCP library.

@battuashwik
Copy link

Completely missed this in the mentioned libraries. Thanks a lot for the help.

@syalujjwal
Copy link
Author

Its great that now this is into consideration. Just wanted to know how can
I come to know about the new updates and development on this, and when the
new feature is alive?

On Sat, May 14, 2016 at 11:30 AM, battuashwik notifications@github.com
wrote:

Completely missed this in the mentioned libraries. Thanks a lot for the
help.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#1420 (comment)

@igrr
Copy link
Member

igrr commented May 16, 2016

@syalujjwal could you please clarify what are you referring to in your last question: ESPAsyncTCP library, or changing client.connect timeout to the same value as client.setTimeout ?

@syalujjwal
Copy link
Author

both are good enough solutions for me. I wish to use a library that allows
me to get control over how much time the client.connect blocks the code
for. Whatever it is that you are working on first, i would love to know
more about it and its availability. :)

On Mon, May 16, 2016 at 4:51 PM, Ivan Grokhotkov notifications@github.com
wrote:

@syalujjwal https://github.com/syalujjwal could you please clarify what
are you referring to in your last question: ESPAsyncTCP library, or
changing client.connect timeout to the same value as client.setTimeout ?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1420 (comment)

@igrr
Copy link
Member

igrr commented May 16, 2016

You can totally use ESPAsyncTCP library right now.

@syalujjwal
Copy link
Author

so cool. Thank you :)

On Mon, May 16, 2016 at 4:57 PM, Ivan Grokhotkov notifications@github.com
wrote:

You can totally use ESPAsyncTCP https://github.com/me-no-dev/ESPAsyncTCP
library right now.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#1420 (comment)

@szpght
Copy link

szpght commented Sep 11, 2016

I have the same problem. I would be grateful for changing client.setTimeout behavior, or a little tip where to look in the code :)

@terryjmyers
Copy link

While I understand the 5 second behavior, I don't want an asyncronous library for my application. What would it take to get a the client.setTimeout function working as one would expect it to?

@jarnolbrown
Copy link

jarnolbrown commented Oct 4, 2017

If this was done in May, how can I update my Arduino IDE installation to include it? I seem to be stuck on 2.3, and I can see from viewing the source files that the client.connect does not use the timeout set by setTimeout, by comparing with the src from the repository. I tried the "staging" option, but that seemed to break everything again, and after a day of uninstalling, re-installing and rebooting, I'm loathe to try it again. I'm not stupid, I've been writing code for over 40 years, but I'm not au fait with all the Git stuff.
Any advice appeciated.

@papadenis
Copy link

Occasionally it happens that the request->client()->close() command fails on the AsyncWebServer, the connection remains open and the client sticks. It's needed to take care of resetting this connection from the client side by timeout. Something like this:

if (client.connected()) {
    client.print(tail);
    int http_code = 0;
    
    unsigned long cnnct_timeout = 5 * ONE_SEC;
    if (!millis_fails(cnnct_timeout, global.millis_range)) {
        unsigned long cnnct_timestamp = millis();

        while ((client.connected() || client.available())
                && millis() < cnnct_timestamp + cnnct_timeout) {
            if (client.available()) {
                String line = client.readStringUntil('\n');
                if (line.substring(0, 8) == "HTTP/1.1")
                    http_code = line.substring(9, 12).toInt();
            }
        }
        if (millis() >= cnnct_timestamp + cnnct_timeout)
            logOutput(global.chipid, "Released by timeout");
    }

    if (http_code != 200)
        uploaded = false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants