Repeat Process To Check Contents of File on HTTP Server?

Phil Davis revdev at pdslabs.net
Mon May 11 03:25:09 EDT 2009


Hi John,

I'm assuming the following things are true:

    * everyone is using Windows, or at least all the kids
    * all the computers have access to the same shared hard disk,
      whether it's a file server or one person's computer.
    * there's a 'GoodLinks' folder on the shared disk where your links
      to web pages go.
    * I actually understand what you want to accomplish (that's probably
      the most iffy part)

On those assumptions, you could do this pretty simply. See if the 
following work flow would accomplish your goal.

First, your actions (or "use case" to make it sound more technical):

   1. The shared disk is mounted on your computer (and on all the client
      computers), and you have a shortcut to the shared 'GoodLinks'
      folder sitting on your desktop.
   2. You find a web page you want to share.
   3. You drag the web page's icon from the browser URL box onto the
      'GoodLinks' shortcut. This creates a "myGreatLink.URL" file in the
      GoodLinks folder on the server/shared disk.

Now the students' actions:

   1. When their computers start, a 'Checker' app (see code below) is
      launched and runs quietly in the background.
   2. Checker looks at the names of files in the 'GoodLinks' folder on
      the shared disk every x seconds (using the "send... in" command).
      When it finds a new file, it launches it.

I think that's everything. Now the code:


-- Checker stack script
on openStack
  send "checkForLinks" to me in 5 secs
end openStack


on checkForLinks
  -- get all link names
  set the defaultFolder to "X:/GoodLinks"
  put the detailed files into tList

   -- pick the most recently created link
  filter tList with "*.URL,*" -- to remove non-links from list
  sort lines of tList numeric descending by item 4 of each
  put line 1 of tList into tMostRecentLink
  put item 4 of tMostRecentLink into tMostRecentUpdate

  -- open link in browser if link is new
  if tMostRecentUpdate > (the seconds - 5) then
    launch document (urlDecode(item 1 of tMostRecentLink))
  end if

  -- schedule next execution
  send "checkForLinks" to me in 5 secs
end checkForLinks


A few points about this approach:

    * This way you don't need to store any previous values.
    * the code assumes that everyone's computer times are close to
      correct. If some student computer has their clock set to yesterday
      or tomorrow or last year, this code won't work as expected.
    * If you're using Macs in the classroom you'll probably need to
      change the "filter" command to look for a different file type
      (maybe .webloc), but otherwise it should work.
    * you notice there's no use of http or sockets - it's all done with
      file references.

I hope I got the problem right! I think accurate problem definition is 
about 70% of the solution.
Phil Davis


John Patten wrote:
> Thanks Phil and Bjoernke!
>
> That's what I needed..."send" command. Seems so obvious when you see 
> someone else explain it :-)
>
> Now, that I understand send, here's my dilemma. What I'm trying to 
> create is a little app that allows a teacher in the classroom to push 
> out a web site they have loaded in their "teacher" browser out to to 
> all 32 student laptops in their classroom. I thought this would be a 
> perfect implementation for revBrowser, a custom web browser.  I 
> remember in the past struggling with Rev and opening sockets to try to 
> get two Rev stacks to talk to each other. I never had very much 
> success with that process so I thought I would try to keep it real 
> basic and utilize web sharing and writing out a text file with the 
> teacher's current web site address and time stamp to the local "web 
> sites" folder. The client (student) computers would check that text 
> file every 5 seconds, continually, and then if the time stamp is 
> different from the last web address and time stamp, load the new web 
> address in the client (student) browser.  The key word in those run on 
> sentences is "continually."
>
> In the examples shared, the scripts handlers are opencard and 
> mousedown. They only run, essentially, one time through and after the 
> time stamp is different, the script would end.
>
> I started to mess with an idle handler, but that gets messy real 
> quick. Is what I'm describing possible? To have a script run 
> continually in the background over and over?  Or, maybe I'm going at 
> this custom teacher to student web browser thing all wrong? Any ideas 
> greatly appreciated!
>
> Thank you!
>
> John Patten

-- 
Phil Davis

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




More information about the use-livecode mailing list