如何在REBOL3中打开/写入/读取端口?

时间:2015-02-12 15:01:49

标签: rebol rebol3 rebol2

我在REBOL2中有这段代码:

port: open/direct tcp://localhost:8080
insert port request
result: copy port
close port

REBOL3中的内容是什么?

1 个答案:

答案 0 :(得分:5)

REBOL3网络默认为异步,因此REBOL3中的代码必须如下所示:

client: open tcp://localhost:8080
client/awake: func [event /local port] [
    port: event/port
    switch event/type [
        lookup  [open port]
        connect [write port to-binary request]
        read [
           result: to-string port/data
           close port
           return true
        ]
        wrote [read event/port]
    ]
    false
]
wait [client 30] ;the number is a timeout in seconds
close client 

基于:http://www.rebol.net/wiki/TCP_Port_Examples

编辑:以上链接不再存在,但这里是转移到GitHub的wiki:https://github.com/revault/rebol-wiki/wiki/TCP-Port-Examples