Hi Charles,

This script has a bit of a bizarre style
to it. It looks like you are using the
error handling to decide whether to open
a client or server. (If there's an
error opening the server a second time,
then become a client).
So you must run the script, press escape,
then run again to open the client.
This is hard to understand and I don't
recommend it.
Better to separate the script into two
clearly defined parts: server and client.

It looks like you are also setting the server
and client to use the same handler code.
(I know, not the same instance of the handler,
but still the same code.)
So client and server are each waiting for the
other to write something, so nothing happens ! :)

On 'connect, client should send a request to the
server, server will 'read this, then 'write back to the
client, and the client will 'read that.

Anton.

> I have been playing with Both the async-protocol and the atcp-protocol
> with no real success. I will post the atcp snippet in the next email.
> 
> When using the async-protocol, it seems like the event handler never
> kicks off but the listen/awake function kicks seems to accept at least 1
> connection because it prints "connection"
> 
> Any suggestions?
> 
> 
> 
> Rebol [
> 
>       Title: none
> 
>  ]
> 
> do %/d/projects/rebol/async-protocol.r
> 
> either error? try [listen: open/no-wait tcp://:8000] [
>   port: open async://localhost:8000
>   port/awake: do handler
> ] [
>     listen/awake: func [l /local p] [
>       print "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] [=20
>   if error? :state [print mold disarm state return true]
>   switch state [
>    =20
>     connect [print "connected event"]
>    =20
>     read    [
>               append buffer copy port
>               while [tmp: find buffer newline] [
>                 cmd: copy/part buffer tmp
>                 remove/part buffer next tmp
>                 print cmd
>               ]
>               false
>             ]
>     write   [false]
>     close   [print "Connection Closed. " close port true]
>   ]
>   ]
>   ]
> ]
> 
> forever [wait []]

-- 
To unsubscribe from the list, just send an email to rebol-request
at rebol.com with unsubscribe as the subject.

Reply via email to