We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › loadstrings("url") with try catch(Except
Page Index Toggle Pages: 1
loadstrings("url") with try catch(Except (Read 946 times)
loadstrings("url") with try catch(Except
Mar 17th, 2007, 10:30pm
 
hi,

I need to read a string which is incrusted into a webpage on a remote http server every 15 minutes. I can't alter anything on the server side.

LoadStrings() works for this so long as there are no connection errors. I've added the  "try - catch" expression so that in the event of an error the graphics in my application keep on moving. This seems to work if the remote server is down or if the URL is wrong, but doesn't work (the graphic animation freezes) if my local internet access is off.

Is there a way around this? Or maybe there's a faster & more effective way of grabbing a string from a http server?


Re: loadstrings("url") with try catch(Ex
Reply #1 - Mar 18th, 2007, 12:40pm
 
If your local network connection is down, the connection will wait, as it can't tell the difference between no netwok connection, and the other end just being a bit slow.

I don't know if it's possible to set a timeout on the connection to make it quicker.

One option is to wrap your loading function into a class, and make it mutli-threaded, so that your sketch keeps on running, whilst the other thread tries to load the data you want. There should be a couple of references to writing a threaded calss in the reference if you do a search.
Re: loadstrings("url") with try catch(Ex
Reply #2 - Mar 19th, 2007, 10:56pm
 
Thanks alot for the pointer John,
It's good to find out about threaded classes...

Happily, there's also a library by Daniel Shiffman called simpleML that does the same thing (but makes it really easy for newbies like myself)

http://www.shiffman.net/teaching/simpleml/
Page Index Toggle Pages: 1