Hello [EMAIL PROTECTED],


This might be the problem

>> ? read-io
Low level read from a port.
Arguments:
    port -- Already opened port to read from. (port)
    buffer -- Buffer to which to append data. (series)
    length -- Maximum number of chars to read. (number)
->            ^^^^^^^


Try this:
    my-read-function: func [port buf size] [
        clear buf
        while [< length? buf size] [
            append buf copy/part port (size - (length? buf))
        ]
        length? buf
    ]

(with this function you will need to open the port with open/binary)


Best regards
Thomas Jensen


On 21-Dec-99, [EMAIL PROTECTED] wrote:

> For a challenge, and because BeOS hasn't got a client, I'm
> attempting to write a napster client in REBOL.
> 
> Napster sends data in a format that has a two byte binary
> length, followed by a two byte binary message code  then
> a string thats the two byte binary length long.
> 
> I'm using read-io to get these from the server, however
> read-io occassionally gets one less byte than expected.
> here's a code snippet...
> 
>     Response: make binary! 2
>     read-io Napster Response 4
>     
>     print Response
> 
>     ; napsters server suffers from byte reversal !!    
>     ResponseLength: (to-integer first Response) + (256 * (to-integer 
> second Response))
>     ResponseCode: (to-integer third Response) + (256 * (to-integer 
> fourth Response))
>     print ResponseCode
>     print ResponseLength
>     
>     Response: Make string! ResponseLength
>     read-io Napster Response ResponseLength
>     
>     
>     either ResponseCode = 3
>     [
>         print Response
>         print " Login okay!"
>     ]
>     [
>         print "Login Failed"
>     ]
> 
> 
>     Response: make binary! 2
>     read-io Napster Response 4
>     print Response
> 
> 
> and the output...
> 
>     #{10000300}    
>     3
>     16
>     [EMAIL PROTECTED]
>     Login okay!
>     #{6D}
>     ** Script Error: Out of range or past end.
>     ** Where: to-integer second Response                
> 
> 
> as you can see, the length is 16 (3 is the message code) but the data 
> pulled back is 
> "[EMAIL PROTECTED]" is only 15 bytes long, the 'm' from .com is received 
> when the
> script is expecting the next response.
> 
> Can any one see anything that I'm doing incorrectly or might this be a 
> bug ????
> 
> Dave
> 

Reply via email to