AltME: R3 Protocols

Messages

Rebolek
This should be it. It waits until timeout and then returns data:
send-redis-request: func [port] [
    write port #{2A330D0A24330D0A5345540D0A24390D0A6173796E63746573740D0A24340D0A747275650D0A}
]
read-redis: func [
    "Async HTTP reader"
    url [url!]
    /local spec port
][
    spec: probe decode-url url
    spec/2: to-lit-word 'tcp
    port: open spec
    port/awake: func [event] [
        ;print ["Awake-event:" event/type]
        switch/default event/type [
            lookup [open event/port]
            connect [send-redis-request event/port]
            wrote [read event/port]
            read  [
                print ["Read" length? event/port/data "bytes"]
                read event/port
            ]
            close [return true]
        ] [
            print ["Unexpected event:" event/type]
            close event/port
            return true
        ]
        false ; returned
    ]
    port
]
print "REDIS reading..."
rp: read-redis tcp://192.168.211.10:6379
wait [rp 10]
close rp
print to-string rp/data
It's adapted from the HTTP example where it works fine, but with another scheme I can't get it to work.
GrahamC
Sorry, does the above work or not?
Rebolek
It sort of works. Request is send and response is read back but instead of returning immediately, it waits for timeout. The HTTP example from rebol.net wiki returns immediately.
GrahamC
read  [
                print ["Read" length? event/port/data "bytes"]
                read event/port
            ]
Here you need to print the event data and return true .. not read again
You are timing out because you are attempting to read again from the port when no more data is coming
Rebolek
So why does it work in HTTP example?
Also, changing the READ code to:
            read  [
                print ["Read" length? event/port/data "bytes"]
                true
            ]
does nothing. It still waits until timeout.
GrahamC
the http protocol uses two event engines .. it's complicated
Does it print any data?
Rebolek
yes, it prints instantly and then waits 10 seconds.
GrahamC
change that to . return true and not just true
you still have false at the end of your loop
Rebolek
Wow!
Oh, I see...
Thanks, Graham!
GrahamC
Or, restructure your loop the same way as I did
NP .. still waiting on text-table and text-list fixes :)
Rebolek
I know, I''m sorry...I'm spending too much time with Redis ;)

Last message posted 486 weeks ago.