[REBOL] async:// Close connection
From: tbrownell::veleng::com at: 4-Mar-2004 9:41
When I use the following example from the tutorial, my server stop whenever a client
disconnects with this message...
async protocol loaded
Got connection.
Peer closed connection.
>>
rebol []
do %async-protocol.r
either error? try [listen: open/no-wait tcp://:3000] [
port: open async://localhost:3000
port/awake: do handler
] [
listen/awake: func [l /local p] [
print "Got connection."
p: first listen
remove find system/ports/wait-list listen
port: make port! [scheme: 'async sub-port: p]
open port
port/awake: do handler
false
]
insert tail system/ports/wait-list listen
port: none
]
handler: [ use [ buffer ][
buffer: copy []
func [port [port!] state [word! error!] /local tmp cmd] [
if error? :state [print mold disarm state return true]
switch state [
connect [print "Connected." false]
read [
append buffer copy port
while [tmp: find buffer newline] [
cmd: copy/part buffer tmp
remove/part buffer next tmp
do-cmd cmd
]
false
]
write [false]
close [print "Peer closed connection." close port true]
]
]
]
]
do-cmd: func [cmd] [
other/color: attempt [load cmd]
show other
]
view layout [
across me: box 100x100 random 255.255.255 0:00:01 feel [
engage: func [f a e] [
if a = 'time [
me/color: random 255.255.255
if port [insert port join me/color newline]
show me
]
]
]
other: box 100x100 random 255.255.255 Return
Area 208x100
]
halt
Terry Brownell wrote:
>>Using the server example in the doc, the server stops once the client
>>disconnects?
>>
>>Terry
>>
>>
>
No, it closes the connection with this particular client only.
--Maarten