Repeat Process To Check Contents of File on HTTP Server?

Phil Davis revdev at pdslabs.net
Thu May 7 02:31:52 EDT 2009


John Patten wrote:
> Hi All!
>
> I'm making a little web browser client that needs to check the 
> contents of a file on a web server. It needs to be able to do this 
> every 5 seconds or so in the background, and then if the contents 
> changes in the last line of the file it is checking, it starts another 
> process in the background. Can this be done in Rev? Would I use two 
> stacks, one as the browser and one with the repeat loop?
>
> I'm at a loss for what this might look like in a script?

Hi John,

Are you familiar with the "send" command? If not, I think you're about 
to be... ;o)


-- prep: since you're looking for a change in data values,
-- you need to store its initial value so you have something
-- to compare to
global gOriginalData


-- and the data check has to be put into motion:
on openCard
   -- store initial value
   put url "http://my.website.com/targetfile.txt" into gOriginalData
   -- put the data check into motion
   send "checkWebFile" to me in 5 secs
end openCard


-- the data check
on checkWebFile
   -- get fresh copy of the data
   put url "http://my.website.com/targetfile.txt" into tCurrData
   if (last line of tCurrData <> last line of gOriginalData) then
      send ("startOtherProcess" && tCurrData) to me in 1 sec
   else -- data hasn't changed, so schedule another check
      send "checkWebFile" to me in 5 secs
   end if
end checkWebFile


-- the other background process
on startOtherProcess pChangedData
   -- do your other stuff here
end startOtherProcess


The "send... in" construct 'disconnects' the calling and called handlers 
from each other, so the calling one can finish executing before the 
called one starts. And by saying "in 5 secs", you insert idle time when 
the UI can be refreshed & interacted with. It keeps the user from being 
locked out of the UI due to continuous running of code you might have if 
you tried using a repeat loop for data checks.

Hopefully this will get you started.

>
> Thanks in Advance!
>
>
> John Patten 

-- 
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net




More information about the use-livecode mailing list