[EMAIL PROTECTED] wrote: > > A while ago I posted a script with functions to message back and forth > between two rebol scripts, but which didn't work reliably for some reason. > I don't know why it didn't work, but Bo sent me an example script which I > used to fix my problem. Since there was some interest I'll post this one. > The difference from my last attempt is that this one keeps the connections > open, while the last one closed them and reopened them all the time. Also > this one reads the messages one byte at a time. As a result this one is > much slower, but it's ok for simple messages at least. I've modified this so that it sends along the length of the data being sent, so instead of looking for endofchar, it can use read-io directly which is mucho faster :) Only the transmit & receive functions are changed, with the most damage being done in receive. Julian Kinraid
REBOL[ Title: "netmsgtest" Date: 2000-04-28 Author: "Johan Rönnblom / Bohdan Lechnowsky" Purpose: {functions for sending messages between two rebolscripts} ] transmit: func [info /local str][ str: mold info ; Prepend a 4 byte value containing the length str: join (debase/base (to-hex length? str) 16) str append outport str ] receive: func [/local total-len len][ wait inport len: total-len: to-integer to-binary copy/part inport 4 data: make string! total-len ; If the data is sent in chunks, keep reading until all the data has been read until [ read-io inport data len len: total-len - length? data len <= 0 ] return do data ] setup: func [][ endchar: to-char 255 otherurl: ask "Enter remote url: " either error? try [outport: open/binary/direct to-url rejoin [tcp:// otherurl ":8000"]][ mode: "server" conn: open/binary/direct tcp://:8000 wait conn inport: first conn outport: open/binary/direct to-url rejoin [tcp:// otherurl ":8001"] ][ mode: "client" conn: open/binary/direct tcp://:8001 wait conn inport: first conn ] ] setup if mode = "client" [transmit "1"] forever[ a: receive print a transmit ((to-integer a) + 1) ]