AltME: R3 Protocols

Messages

Cyphre
I think first you need to know how much you read already, how much is left to read, if you are at the end of the response or not etc. and build logic around that in the awake handler. What protocol are you trying implement?
Also look at the examples...I don't remeber it from my head directly but you can either read or write on the port from the READ event depending if you want to wait for more data or send something to the server etc. It all depends on the protocol definiton.

Gabriele
Rebolek, IIRC you just call READ again on the port if you want to read more in the 'read event. That will trigger a new 'read event once new data is ready. You should check existing examples (eg. HTTP), I don't know what the state of the documentation is.

Rebolek
Gabriele, Cyphre, see this gist. https://gist.github.com/rebolek/8858338 It returns first line but when I call read again it just waits and does nothing.
Gabriele
What I meant is, that in the 'read event:
    read [
        port/spec/data: copy port/data
        clear port/data
        return true
    ]
you need a way to know if more data is needed (or, simply assume more data is always needed) and call read again, eg:
    read [
        port/spec/data: copy port/data
        clear port/data
        read port
        return true
    ]
this will trigger a new 'read event where you call COPY again etc.
This is from memory so I might be wrong.
Gabriele
For example, in the HTTP scheme, in the 'read event I call the check-response function, which determines if more data is needed (do we have all the headers? do we need content data? etc.) and calls READ on the port accordingly.
actually, I think that returning TRUE from the 'read event means "we are done, no more data to read", which signals the higher level READ to return your data. But, I might be wrong here, I don't remember the details.
Rebolek
Ah, OK, so calling READ from READ. I will try that. Thanks.
Cyphre
Yes, I think Gabriele is right...you need to call READ action from READ event. AFAIK you can also WRITE on port from READ event to send some data to server if necessary...etc.  It depends on the protocol spec/logic you need to follow.

Bo
GrahamC: I was trying to use your excellent FTP protocol for R3 from https://github.com/gchiu/Rebol3/blob/master/protocols/prot-ftp.r, but I am getting an error when I am trying to read or load:
>> read ftp://user:pass@ftp.sonic.net/
** Script error: cannot access state in path port/state/connection
** Where: read
** Near: read ftp://user:pass@ftp.sonic.net/
>> load ftp://user:pass@ftp.sonic.net/
** Script error: cannot access state in path port/state/connection
** Where: read either read-decode case load
** Near: read source if find system/options/file-types type [data: de...
I was wondering if this is a known issue or a regression?
The same port/state/connection error shows up when trying to write a file as well.
Bo
This is with the latest Windows build downloaded today from http://rebolsource.net.
NickA
Bo, you need to use the FTP protocol commands to read or save (you can't do it directly with 'read, 'write, 'load, etc.).  There are some working examples at  http://learnrebol.com/rebol3_book.html#section-7.9 and http://learnrebol.com/rebol3_book.html#section-7.10
Bo
Ah, thanks for that, Nick!
GrahamC
Yes, synchronous mode working on a url is not currently supported.  You need to work with a port!
Never got round to finishing the protocol.
There was no interest in 2010 lol
But I think it's easy enough to wrap them into a synchronous function

amacleod
Getting an eror trying to open ftp port using prot-ftp.r
cmd: open decode-url ftp://user:pw@majorityreporttv.com
Script error: net-log has no value
Where: open
GrahamC
doesn't use 'decode-url
amacleod
Will try again Graham, Thanks. I was working from NIck's tutorial...

amacleod
Graham, similar error.
cmd: open ftp://user:pw@majorityreporttv.com
Script error: net-log word is not bound to a context
Where: open
I'm doing: do prot-ftp.r or is it a module that should be included in needs[]: ?
Not up to speed with R3...

Last message posted 155 weeks ago.