tags:

views:

108

answers:

2

I tried http://www.mail-archive.com/[email protected]/msg19437.html (I just changed to www.reboltutorial.com) :

do http://www.rebol.it/giesse/async-protocol.r

handler: func [port [port!] state [word! error!] /local tmp cmd] [
    if error? :state [print mold disarm state return true]
    switch state [
        connect [
            ; do HTTP request
            insert port {GET /files/2009/10/word.png HTTP/1.0^M^JHost: 
www.reboltutorial.com^M^J^M^J} 
            false
        ]
        read    [false]
        write   [false]
        close   [
            ; get data
            data: copy port
            close port
            ;print copy/part data find data "^M^J^M^J"
            data: to binary! find/tail data "^M^J^M^J"
            other/image: attempt [load data]
            other/text: ""
            show other
            false
        ]
    ]
]

port: open async://www.reboltutorial.com:80
port/awake: :handler

view layout [
    across me: box 100x100 random 255.255.255 0:00:00.5 feel [
        engage: func [f a e] [
            if a = 'time [
                me/color: random 255.255.255
                show me
            ]
        ]
    ]
    other: box 100x100 255.255.255 "Downloading image..." Return
    Area 208x100 "You can type here while downloading."
]

]

But I'm getting this error:

>> port: open async://reboltutorial.com:80
** Access Error: Invalid port spec: async://reboltutorial.com:80
** Near: port: open async://reboltutorial.com:80
>> port/awake: :handler
** Script Error: port has no value
** Near: port/awake: :handler
+1  A: 

Use Romano's protocol and see if that works for you as it does for me.

http://www.rebol.it/romano/atcp-protocol.r

Graham Chiu
+2  A: 

This from Gabriele, the author of the async-protocol showing async http fetching his home page.

>> do http://www.colellachiara.com/soft/libs/async-protocol.r
connecting to: www.colellachiara.com
Script: "async:// protocol (Asynchronous TCP)" (8-Feb-2005)
async protocol loaded
asyncs protocol loaded
>> do http://www.colellachiara.com/soft/libs/async-http.r
connecting to: www.colellachiara.com
Script: "Asynchronous HTTP protocol for REBOL" (8-Feb-2004)
ahttp protocol loaded
ahttps protocol loaded
>> p: open ahttp://www.rebol.com/
>> p/awake: func [port [port!] event [error! word!]] [if event = 'close [print copy port return true] false]
>> wait []
<!doctype html>
<html><head>
<meta name="generator" content="REBOL WIP Wiki"/>
<meta name="date" content="7-Jun-2010/15:05:53-7:00"/>
<meta name="rebol-version" content="2.100.97.4.2"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta http-equiv="Pragma" content="no-cache" />
Graham Chiu
Hi Graham, thank you very much.
Rebol Tutorial
I've created a GUI example here http://rebol.wik.is/Protocols/Test-async-http.r and you can get the updated async-http.r from http://github.com/gchiu/Rebol2/blob/master/Protocols/prot-ahttp.r ( note the name change ). The example does a download with progress meter, and display of the number of characters being downloaded. No error handling though.
Graham Chiu
Hi I tried it and got an error seehttp://stackoverflow.com/questions/3076236/error-with-test-async-http-r-in-rebol
Rebol Tutorial