[Improvements to web documentation sydow@chalmers.se**20081116201927] { move ./tests/PingTimeServers.t ./examples/PingTimeServers.t hunk ./examples/Makefile 3 -EXAMPLES = Echo Echo2 Echo3 EchoServer EchoServer2 MasterMind Primes Reflex TCPClient +EXAMPLES = Echo Echo2 Echo3 EchoServer EchoServer2 MasterMind Primes Reflex TCPClient PingTimeServers hunk ./examples/PingTimeServers.t 14 -check neterror report sock = class +client neterror report sock = class hunk ./examples/PingTimeServers.t 17 - sock.outFile.write "Hi!" hunk ./examples/PingTimeServers.t 38 - env.inet.tcp.connect (Host (env.argv!i)) port (check (report i) (report i)) + env.inet.tcp.connect (Host (env.argv!i)) port (client (report i) (report i)) hunk ./examples/Reflex.t 20 - msg <- after (sec 2 + millisec (r `mod` 2000)) action + waitingTime = sec 2 + millisec (r `mod` 2000) + msg <- after waitingTime action hunk ./web/Echo3_descr.html 49 - is no ackumulating drift in the program, even if a particular tick may be delayed in + is no accumulating drift in the program, even if a particular tick may be delayed in hunk ./web/Echo_descr.html 75 -Echo2 for a more careful description.) +Echo2 for a more careful description.) hunk ./web/MasterMind_descr.html 8 -MasterMind is a board game with two players; in this +MasterMind is a board game with two players; in this hunk ./web/MasterMind_descr.html 35 -
  • The program makes use of two auxiliary modules - Data.Functional.List and RandomGenerator. The - former is a library module, while the latter is provided in the - examples directory. +
  • The program makes use of two library modules + Data.Functional.List and RandomGenerator. These +> are parts of the (presently very experimental) Timber library. hunk ./web/MasterMind_descr.html 112 - gen := Nothing -- We don't yet have access to a good seed + gen = new baseGen (microsecOf env.startTime) hunk ./web/MasterMind_descr.html 119 - Just g = gen - r <- g.next + r <- gen.next addfile ./web/PingTimeServers_descr.html hunk ./web/PingTimeServers_descr.html 1 + + + +PingTimeServers + + + +

    PingTimeServers

    +

    +Another network client, that asks a number of network time servers, +listed on the command line, for current time. Here is a sample +run: +

    +examples> ./PingTimeServers time.nist.gov time-a.nist.gov time.ien.it dummy localhost
    +dummy: Name lookup error
    +localhost: Connection failed
    +time-a.nist.gov: 
    +54786 08-11-16 16:51:48 00 0 0 254.7 UTC(NIST) * 
    +
    +time.ien.it: Sun Nov 16 17:51:47 2008
    +
    +time.nist.gov: no response
    +examples> 
    +
    +

    The program connects to servers that use the old Daytime Protocol, +listening on TCP port 13. +The three first arguments above are existing time servers. Two of +these responded quickly with time in this run, while +time.nist.gov +did not respond within two seconds. The fourth argument is a +nonsense URL that the name server will not identify and the final +argument, localhost, is a valid host which will probably not run +a time server. +

    +Here is the program: +


    +
    +module PingTimeServers where
    +
    +import POSIX
    +import Data.Functional.List
    +
    +port = Port 13  -- standard port for time servers
    +
    +client neterror report sock = class
    +
    +    established = action
    +       sock.inFile.installR report
    +
    +    close = request result ()
    +
    +    result Connection {..}
    + 
    +
    +root env = class
    +
    +    args = [1..size env.argv-1] 
    +    print i mess = env.stdout.write
    +                      (env.argv!i ++ ": "++ mess ++ "\n")
    +
    +    outstanding := args
    +
    +    report i mess = action
    +       outstanding := delete i outstanding
    +       print i mess
    +       if (null outstanding) then env.exit 0
    +    
    +    result action
    +       forall i <- args do
    +          env.inet.tcp.connect (Host (env.argv!i))
    +                               port
    +                               (client (report i) (report i))
    +       after (sec 2) action
    +          forall i <- outstanding do 
    +             print i "no response"
    +          env.exit 0
    +
    +
    +
    +

    +Comments to the code: +