From a4baedf72d3abfe9f74ee1dade09a454c0ae7c00 Mon Sep 17 00:00:00 2001 From: dos-reis Date: Wed, 7 Jan 2009 07:54:17 +0000 Subject: * 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. --- contrib/examples/time-client.input | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 contrib/examples/time-client.input (limited to 'contrib') 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 -- cgit v1.2.3