Timeout for URL::readEntireTextStream()


#1

Hey,

I'm currently using URL::readEntireTextStream() to grab the text from a PHP file online.

All works fine unless I'm connected to a wifi/network connection where there is a problem with the internet connection, where this function just hangs for a noticeably long time. 

Is there any way I can add a timeout to the function or object so that I can set how long it tries to read the PHP file, or a way to determine if the internet connection is working correctly?

Thanks.


#2

If you create the stream directly with URL::createInputStream, you can give it a time-out to use.


#3

Perfect! Thanks for the quick response Jules.


#4

I"ve applied a 7000ms timeout on OSX and this: 

    void run() override

    {

        connection = [[NSURLConnection alloc] initWithRequest: request

                                                     delegate: delegate];

        while (! threadShouldExit())

        {

            JUCE_AUTORELEASEPOOL

            {


                [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];

            }

        }

    }

Doesn't seem to want to return from NSURLConnection, at all, as far as I can tell!

There's a bit of moaning about timeouts, though mainly from IOS developers, on the internet.  So I'm going to try a bigger number for the timeout and see if that helps.   But if anyone else has hit this I'd be interested... ?