aboutsummaryrefslogtreecommitdiff
path: root/contrib/examples/time-client.input
blob: 4bb9dcbdbfcf417892ded82ebf15819dfd27ec12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env open-axiom

-- This little script is a simple example of how to use
-- the client socket domain in OpenAxiom.
-- It connects to a time server, read the time and print it 
-- on the standard output.
-- Contributed by Gabriel Dos Reis.

s := connectTo(host "time-a.nist.gov", port 13)$INETCLTS

-- Give up if conection failed.  We try only once.
s case nothing => 
  print message("connection failed")$OutputForm

-- Read initial linefeed character
readByte! s case nothing => 
  messagePrint("could not read first linefeed character")$OutputForm

text := empty()$ByteBuffer   -- container of the actual line
buf := byteBuffer 256        -- temporary buffer to read into

-- Accumulate data until end of input.
while readBytes!(s::INETCLTS,buf) > 0 repeat
  text := concat(text,buf)
close! s

-- Show what we got.  We should actually try to remove last
-- linefeed character.
messagePrint(text::String)$OutputForm