Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

A better way?

 [1/4] from: tbrownell::l3technology::com at: 6-Feb-2003 10:04


Is the following bit o' code the most efficient way of continuously "doing" things (In this case, continuosly monitoring yahoo and rebol web servers with forever loops)? What's happening here anyway? You would think that it would hit a forever loop and that would be the end of that script. Is it generating multiple threads with each button or ? =TBrownell rebol [] view layout [ aa: box blue 25x25 btn "Yahoo" [forever [wait 10 either error? try [read http://www.yahoo.com] [aa/color: red show aa] [aa/color: green show aa] ] ] btn "Rebol" [forever [wait 10 either error? try [read http://www.rebol.com] [aa/color: red show aa] [aa/color: green show aa] ] ] btn "Other" [print "something else"] ] P.S. Rebol website visitor logs may be artificially heightened ;)

 [2/4] from: greggirwin:mindspring at: 6-Feb-2003 14:35


Hi Terry, Check out the following script and see what you think. -- Gregg REBOL [ Title: "Handy Server Monitor Window" Date: 2-May-2002 Version: 1.0.0 File: %monitor.r Author: "Carl Sassenrath" Purpose: {A handy script that monitors various servers (such as web and email servers) and displays them in a nice little status window. } Email: [carl--rebol--com] Category: [net tcp web view] ] sleep-time: 60 ;-- Main window layout: window: layout [ style lab text 100x24 right middle style inf info 200 font-color white style err info 40 center across origin 8 space 4x4 h2 "Server Monitor" return lab "Status:" t1: info 200 "Initializing" text "Errs" center bottom 40x24 bold return l2: lab "Email Port:" t2: inf 200 e2: err return l3: lab "Web Server:" t3: inf 200 e3: err return l4: lab "Docs Server:" t4: inf 200 e4: err return l5: lab "CGI Script:" t5: inf 200 e5: err return ] ;-- Set error counts: foreach face [e2 e3 e4 e5] [set in get face 'text 0] ;-- Window update functions: start: func [lab str] [ stat none none str lab/color: gold show lab ] done: func [lab] [ lab/color: none show lab ] count-error: func [face] [ face/text: face/text + 1 show face ] stat: func [face 'status str] [ t1/text: str show t1 if face [ face/text: str face/color: select [ok 0.130.0 bad 150.0.0] status show face ] ] check: func [face title block /local info err] [ if none? info: find window/pane face [exit] set [info err] next info start face reform ["Connecting to" title] either error? try block [ stat info bad reform ["Failed:" title] count-error err ][ stat info ok reform [title "Ok"] ] done face ] view/new window forever [ ;-- Clear all status boxes: foreach face [t2 t3 t4 t5] [ face: get face face/color: black face/text: "" show face ] ;-- Try to connect via tcp to known address: check l2 "TCP Email Port" [ close open [ scheme: 'tcp host: 208.201.243.114 port-id: 25 ] ] ;-- Try connect and request from HTTP servers: check l3 "REBOL Web Server" [read http://www.rebol.com] check l4 "REBOL Tech Server" [read http://www.reboltech.com] check l5 "CGI Test" [ read http://demo.rebol.net/cgi-bin/test.r ] ;-- Count down to next check: repeat n sleep-time [ wait 1 if not viewed? window [quit] ; in case window was closed stat none none reform ["Checking in" sleep-time - n "seconds"] ] ]

 [3/4] from: tbrownell:l3technology at: 6-Feb-2003 14:44


Gregg, I just used the server monitor as an example of launching "forever" loops from within the main window. What I don't understand is how you can do a forever loop after doing the view/new window? Or if calling forever loops with a button from within the main window is the most efficient way of doing this. For example, "Handy Server Monitor Window" has a forever loop after the windwow call.. but the following example chokes?? rebol [] a: layout [b: box btn [print "test"] ] view/new a forever [either error? try [ read http://www.rebol.com][b/color: red show b][b/color: green show b]] ;------ Terry

 [4/4] from: greggirwin:mindspring at: 6-Feb-2003 16:30


Hi Terry, TB> I just used the server monitor as an example of launching "forever" loops TB> from within the main window. What I don't understand is how you can do a TB> forever loop after doing the view/new window? Or if calling forever loops TB> with a button from within the main window is the most efficient way of doing TB> this. If you use a FOREVER loop after VIEW/NEW, you need a WAIT in there. Now, once you've got a WAIT in there (which is basically all DO-EVENTS does), you don't want to have another loop with a WAIT inside *that* going on inside your main loop. I.e. you don't want to call WAIT recursively; bad things will happen. TB> For example, "Handy Server Monitor Window" has a forever loop after the TB> windwow call.. but the following example chokes?? You need a WAIT in your code to allow system events to be processed. a: layout [b: box btn [print "test" unview halt]] view/new a forever [ prin "testing..." either error? try [read http://www.rebol.com][ b/color: red show b ][ b/color: green show b ] print "done!" wait 10 ] -- Gregg