如何在 REBOL3 中 open/write/read 移植?
How to open/write/read port in REBOL3?
我在 REBOL2 中有这段代码:
port: open/direct tcp://localhost:8080
insert port request
result: copy port
close port
在 REBOL3 中什么是等效的?
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
编辑:以上 link 已不存在,但这里已转移到 GitHub 的维基:https://github.com/revault/rebol-wiki/wiki/TCP-Port-Examples
我在 REBOL2 中有这段代码:
port: open/direct tcp://localhost:8080
insert port request
result: copy port
close port
在 REBOL3 中什么是等效的?
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
编辑:以上 link 已不存在,但这里已转移到 GitHub 的维基:https://github.com/revault/rebol-wiki/wiki/TCP-Port-Examples