I finally managed to get the client and server working with Anton's
support.
I don't fully understand the callback mechanism. Here is the code for
the test server below. Let's say I wanted to print the #'s 1 through a
million but handle the events as they occur. Where would I put my print
statement? Am I wrong in assuming that this is the way the event works.
I would like to put some standard processing in the event loop but have
no idea where to put it.=20
do %/d/projects/rebol/rebolspaces/async-protocol2.r
listen: open/no-wait tcp://:8181
listen/awake: func [l /local p] [
;print "Server: A Client connected"
p: first listen
port: make port! [scheme: 'async sub-port: p]
open port
port/awake: do server-handler
false
]
server-handler: [use [ buffers ] [
=20
buffers: copy []
=20
func [port [port!] state [word! error!] /local tmp cmd buffer] [=20
if error? :state [print mold disarm state return true]
switch state [
connect [
;print "Server: connect"
]
read [
;print "Server: read"
if not find buffers port [append buffers reduce [port
copy ""]]
print ["buffers length:" length? buffers]
buffer: buffers/:port
append buffer copy port
while [tmp: find buffer newline]=20
[
cmd: copy/part buffer tmp
remove/part buffer next tmp
;print ["Server: Recieved:" mold cmd]
print [mold cmd]
]
false ;close port
]
write [
;print "Server: write"=20
false
]
=20
close [
;print "Server: close"=20
close port=20
false
]
]
]
]
]
insert tail system/ports/wait-list listen
port: none
forever [
wait []
]
--
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.