Setting timeout for LoadImage()/LoadBank()

BlitzMax Forums/BlitzMax Programming/Setting timeout for LoadImage()/LoadBank()

Richard Betson(Posted 2013) [#1]
Hi,

I am using the following code to download images off the net.

LoadImage(LoadBank("http::phoenixusc.com/myimage.jpg"))


The problem is if there is no TCP access due to whatever reason the compiled application stalls for about 5 or seconds. Is there a way to set the timeout range so that it's not waiting for the file so long?

Thanks,
- Rich -


GfK(Posted 2013) [#2]
Could you not try opening a stream to the URL first, and if that succeeds, THEN load the image?


Richard Betson(Posted 2013) [#3]
Hi,

I could but I would have the same problem of it hanging up the application if there is no URL resource available. Using Bnetex I also get a delay of about 5 seconds when say opening a TCP stream if there is no stream TCP resource available. I looked over vertex's code and it looks like the problem lies in BRL's stream or socket code.

I might give it a shot to check, but not hopeful.

My gut feeling is that this might be a good use for threading. But I would really like to avoid that as it might not be possible to use in my well developed game (25k+ lines).

- Rich -


Grisu(Posted 2013) [#4]
You could use Brucey's libcurl for such multi-threadding tasks.

I used it to eliminate the "hangs" of my internal updater function.

Some source code can be found here (2 half of the thread):
http://www.blitzbasic.com/Community/posts.php?topic=99640#1172307


BlitzSupport(Posted 2013) [#5]

I also get a delay of about 5 seconds when say opening a TCP stream if there is no stream TCP resource available


In what situation do you get this delay? This, for example, exits immediately for me:

Local image:TImage = LoadImage(LoadBank("http::lalala.madeup/myimage.jpg"))


Failing that, perhaps you could try this code, setting up some Prints to see where exactly it freezes up?




Brucey(Posted 2013) [#6]
In what situation do you get this delay?

It's possible for DNS resolution to be slow under certain circumstances.
So you can't really assume that everything is always going to be instantaneous - especially over the internet.


xlsior(Posted 2013) [#7]
Another possibility is a firewall (like zonealarm) blocking the TCP stream, which will cause the application to time out