[REBOL] rugby type thing
From: ryancole::usa::com at: 26-May-2001 3:01
Hey Maarten,
Here is that script I mentioned the other day that you wanted to see. It
works somewhat, still buggy--very much a work in progress and nothing fancy.
Still needs a port handling report system, to get reports (returned data)
back without waiting around. One neet idea I was implementing was named
orders so you can tell the incoming reports apart, as you could be getting
many back at the same time, same port.
Contrary to some the comments, there is no serial capability.
anyways here it is:
REBOL [
Title: "CAPN Command Accessable Parallel Net"
Description: {
An instance of REBOL evaluates scripts sent by another instance.
Since the script communicates tcp or serial, the instances can
be located on another machine.
}
Usage: {
start rebol on two systems with tcp connectivity and do %capn.r
192.167.1.10 >> comply tcp://:6666
192.167.1.10
192.167.1.20 >> order tcp://192.167.1.20:6666 [ 1000 + 999 ]
192.167.1.20 == 1999
192.167.1.20 >>
}
]
capn: make object! [
comply: function [
Evaluates orders.
listen-url [url!] "TCP or Serial port to listen on."
] [
error
header
rv ; return value
] [
serving-port: open listen-url
forever [
connected-port: first serving-port
header: copy []
until [ (copy header) = append header load get-line connected-port ]
probe header: make object! header
if header/reconnect [ close connected-port ]
if error? rv: try [
mold assume-nothing do load copy/part connected-port header/size
] [
error: true
rv: mold disarm rv
]
reply: rejoin [
size:
length? rv "^/"
error:
error "^/"
throw:
none "^/"
name:
header/name "^/"
type: 'report^/
^/
rv
]
either header/reconnect [
reply-port: open header/report-to
insert reply-port reply
close reply-port
] [
insert connected-port reply
close connected-port
]
]
]
order: function [
Send instruction to complying host.
order-url [url!] "TCP or Serial URL"
data "Data to evaluate"
/no-wait "Dont wait for a reply"
] [
rv
] [
sending-port: open order-url
data: mold data
insert sending-port rejoin [
size:
length? data "^/"
type: 'order^/
catch: no^/
name:
rv: now "^/"
reconnect: no^/
^/
data
]
if not no-wait [ rv: process-report sending-port ]
close sending-port
rv
]
;decide how to wait and no-wait on incoming reports
read-reports: func [
in-port
] [
process-report in-port
]
process-report: function [
sending-port [port!]
] [
] [
connection: wait [sending-port]
header: copy []
until [ (copy header) = append header load get-line connection ] ; cheezy
header: make object! header
rv: load copy/part connection header/size
either probe header/error [
probe header
error: do rv
make error! reform [
*** Could not comply with your order.^/
*** error/type error occured.^/
*** Near: error/near ^/
*** Where: error/where ^/
]
] [
rv
]
]
get-line: function [
Returns a line from a port.
conn [port!]
] [
line
] [
line: copy ""
until [
append line this-char: first conn
#"^/" = this-char
]
line
]
assume-nothing: func [
if argument is unset! returns none, otherwise returns argument.
argument [unset! any-type!]
] [
either value? 'argument [ argument ] [ none ]
]
]
The following is an advertisement, and does not necessarily reflect the viewpoint of
the author: