aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2009-01-07 07:54:17 +0000
committerdos-reis <gdr@axiomatics.org>2009-01-07 07:54:17 +0000
commita4baedf72d3abfe9f74ee1dade09a454c0ae7c00 (patch)
tree315802f081992e649bc4ae09e8b688f5158d41bf /contrib
parentcd753a762cfc0b7067806c794f463a3636c3918e (diff)
downloadopen-axiom-a4baedf72d3abfe9f74ee1dade09a454c0ae7c00.tar.gz
* interp/sys-utility.boot (readByteFromFile): Tidy.
(makeByteBuffer): Set fill pointer. (connectToHostAndPort): Define here. (readByteFromStreamSocket): Likewise. (writeByteToStreamSocket): Likewise. * interp/sys-os.boot (doConnectToHostAndPort): Rename from connectot$NetworkClientSocket. (doReadByteFromStreamSocket): Rename from readByteFromStreamSocket. (doWriteByteToStreamSocket): Rename from writeByteToStreamSocket. * algebra/net.spad.pamphlet: Use Maybe Byte. * algebra/data.spad.pamphlet (ByteBuffer): Fix fill pointer thinko.
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/examples/time-client.input29
1 files changed, 29 insertions, 0 deletions
diff --git a/contrib/examples/time-client.input b/contrib/examples/time-client.input
new file mode 100755
index 00000000..4bb9dcbd
--- /dev/null
+++ b/contrib/examples/time-client.input
@@ -0,0 +1,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