[REBOL] Re: Listener process
From: g:santilli:tiscalinet:it at: 4-Sep-2003 10:21
Hi Gregg,
On Thursday, September 4, 2003, 2:03:28 AM, you wrote:
GI> Here's the basic idea:
Another way to pass the data around:
send-message:
func [port message /only /local res]
[ message: mold/all message
insert insert insert port length? message " " message
if not only
[ if object? res: get-message/only port
[ make error! next next second res]
] ]
buffer: none
get-message:
func [port /only /local pos len message err localbuff]
[ either error? err: try
[ if not string? buffer [buffer: clear ""]
localbuff: make string! 65536
while [not found? pos: find buffer " "]
[ wait port
read-io port localbuff 65534
insert tail buffer localbuff
clear localbuff
]
if integer? len: attempt [to integer! copy/part buffer pos]
[ buffer: next pos
while [len > length? buffer]
[ wait port
read-io port localbuff 65534
insert tail buffer localbuff
clear localbuff
]
message: buffer
buffer: copy skip buffer len
clear skip message len
message: load message
] ]
[ if not only [send-message/only port disarm err]
err
]
[ if not only [send-message/only port 'OK]
message
] ]
They expect the port to be /BINARY. (I'm using READ-IO so /NO-WAIT
shouldn't be necessary. I'm not using COPY because while trying to
find out why it crashed sometimes I tried switching from COPY to
READ-IO and then left it like that. The crash was due to LOAD.)
You can use them to send and receive across a port any REBOL
value. They are blocking, so you just send-message on one side and
get-message on the other side. Use the Storm engine if you need
anything better. :)
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/