【问题标题】:How to open/write/read port in REBOL3?如何在 REBOL3 中打开/写入/读取端口?
【发布时间】:2015-02-12 15:01:49
【问题描述】:

我在 REBOL2 中有这段代码:

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

REBOL3 中的等价物是什么?

【问题讨论】:

    标签: rebol rebol3 rebol2


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多