Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Read-io bug Re:

From: holger:rebol at: 13-Sep-2000 17:18

On Wed, Sep 13, 2000 at 09:00:01AM -0500, [ptretter--charter--net] 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 [holger--rebol--com]