How to open / write / read port in REBOL3?

I have this code in REBOL2:

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

What would be equivalent in REBOL3?

+4
source share
1 answer

The REBOL3 network is asynchronous by default, so the code in REBOL3 should look like this:

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 

Based on: http://www.rebol.net/wiki/TCP_Port_Examples

+5
source

All Articles