CONST NumberOfFilesToDownload
= 1 'Set These for the files you want to continiously download in the background DownloadList(1) = "http://rss.wunderground.com/q/zmw:24138.1.99999"
ON TIMER(Maintimer
, 6) RestartDownload
'This is the time between background refreshes that we want from our webpages/RSS feeds ON TIMER(Downloadtimer
, 0.05) BackgroundUpdate
'This is the timer so we download our information in the background. It's currently set to poll a remote server 20 times per second
TIMER(Maintimer
) ON 'NOTE, when a timer is turned ON, it won't start until AFTER the specified amount of time has passed InitDownloads 'To bypass this initial wait, we manually call InitDownloads ourselves to start the process
IF LEN(DownloadData
(1)) = 0 THEN TimesRefreshed
= TimesRefreshed
+ 1 'Notice TimesRefreshed WON'T increase by one each refresh.
'Our mainloop is making 60 passes per second (as per our LIMIT)
'and the download process only runs 20 times a second.
'There's also the small lag to account for from when we first send data to open the remote server
'to when we get our first data back.
'
'For my test on my PC, this number increments by about 20 (+/-5) each refresh
SUB RestartDownload
'restart the download timer every 60 seconds to refresh download$ in the background. FOR i
= 1 TO NumberOfFilesToDownload
'clear the old files KeepDownloading(i) = 0
DownloadData(i) = ""
CLOSE DownloadHandle
(i
) 'close any old connections (if the remote server hasn't already) InitDownloads 'reopen all those closed handles for fresh transfers
FOR i
= 1 TO NumberOfFilesToDownload
GET #DownloadHandle
(i
), , a$
DownloadData(i) = DownloadData(i) + a$
KeepDownloading(i) = KeepDownloading(i) + 1 'Let's track our number of blank responses
IF KeepDownloading
(i
) > 40 THEN CloseConnection
= CloseConnection
+ 1 'if we get no data from anything for 2 seconds, we stop trying IF CloseConnection
= NumberOfFilesToDownload
THEN TIMER(Downloadtimer
) OFF
FOR i
= 1 TO NumberOfFilesToDownload
DownloadHandle(i) = Opendownload(DownloadList(i))
BackgroundUpdate 'manually call the background service once so we don't wait for the timer
link$ = url$
e$
= CHR$(13) + CHR$(10) ' end of line characters x$ = "GET " + url3$ + " HTTP/1.1" + e$
x$ = x$ + "Host: " + url2$ + e$ + e$
Opendownload = NewsClient