Holger thanks for the reply.  Excellent information on Read-IO.  I would
like to use your comments for my REBOL website Im currently working on.  I
want to go indepth on this subject.  As for Read-io and sending responses -
If data is captured in buffers do you still have the risk of receiving
partial packet information?  Also, what difference does COPY PORT provide in
that respect?

Paul Tretter

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 13, 2000 7:18 PM
To: [EMAIL PROTECTED]
Subject: [REBOL] Read-io bug Re:


On Wed, Sep 13, 2000 at 09:00:01AM -0500, [EMAIL PROTECTED] wrote:
> I finally realized it must be a bug in read-io that causes the Network
> Timeout error message.  Read-io is working fine as long as the server is
> sending data to the client.

Yes, that is intended behavior. Read-io, like all functions to read
data from ports, has a timeout, configurable in
system/schemes/default/timeout.
The default is 30 seconds. If no data is received during that time then
read-io returns a timeout error. You can increase the timeout if 30 seconds
is not enough for your purpose. For IRC you probably want to increase it,
because servers sometimes tend to be slow to respond...

As for read-io not receiving data from the server, chances are the way
you check for it is incorrect. Keep in mind that read-io is a low-level
function that returns contents from TCP packets as they arrive, it does
not attempt to recombine data in any way.

An example: let's say the "pong" response from the server is broken up into
two TCP packets in transit. In that case read-io will return two separate
pieces of data, e.g. one with "po" and the other one with "ng". If you
only check for "pong" in a single reply you received in read-io then you
won't find the response.

This is only one of many reasons why using read-io is not recommended.

IRC is a line-oriented protocol, and for line-oriented protocols REBOL's
copy/insert functions work just fine (even in older versions of REBOL),
so you should use those. Here is an example of how pieces of the network
request/response mechanism in an IRC client could be written. This
particular
example is intended to be used with current experimental versions of REBOL.
To use it with older versions you may have to tweak it a little...


REBOL []

system/schemes/default/timeout: 7200    ; two hours
server: "us.dal.net"
mynick: "q52hw2"
myname: "joe"
mygroup: "#test3636"

scan-input: func [
        /local response
] [
        if not found? response: copy port [
                quit
        ]
        if not empty? response [
                forall response [
                        rp: first response
                        handle-server-string rp
                ]
        ]
]

handle-server-string: func [
        str [string!]
        /local res ret
] [
        space: charset " "
        nonspace: complement space
        prefix: [":" any nonspace some space]
        rules: [0 1 prefix res: any [space | nonspace]]
        if parse/all str rules [
                ret: parse res " "
                if not error? try [to-integer first ret] [
                        print res
                        return none
                ]
                switch first ret [
                        "PING" [
                                print "[responding to ping from server]"
                                insert port rejoin ["PONG" rejoin at ret 2]
                                return none
                        ]
                        "NOTICE" [
                                print rejoin [at ret 2]
                        ]
                ]
                return ret
        ]
        none
]

wait-response: func [
        expected [string! word!]
        /local result rp response
] [
        result: none
        while [not found? result] [
                wait port
                if not found? response: copy port [
                        quit
                ]
                if not empty? response [
                        forall response [
                                rp: first response
                                rp: handle-server-string rp
                                if all [found? rp not found? result] [
                                        result: find first rp expected
                                ]
                        ]
                ]
        ]
]

send-cmd: func [
        data [string!]
        resp [string!]
] [
        insert port data
        wait-response resp
]

irc-port: [
        scheme: 'tcp
        host: server
        port-id: 6667
]

port: open/direct/lines/no-wait irc-port

insert port rejoin ["NICK " mynick]
insert port rejoin ["USER " mynick " 0 * " myname]
insert port rejoin ["JOIN " mygroup]
insert port rejoin ["WHOIS " mynick]
send-cmd rejoin ["PING " server] "PONG"

forever [
        wait port
        scan-input
]


--
Holger Kruse
[EMAIL PROTECTED]

Reply via email to