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

[REBOL] Re: tcp port open?

From: philip:hayes:btcellnet at: 9-Oct-2001 10:21

This is how my tcp-server deals with it wait-ports: none listen-port: open/no-wait/direct/binary tcp://:9999 wait-ports: [ listen-port ] forever [ ; Perform asynch wait !!! wait wait-ports ; Is port descriptor set ? if not ( none? ( wait [ 0 listen-port ] ) ) [ ; Add port to block append wait-ports first listen-port ] ; Set scope of port checking check-ports: next wait-ports ; Check port activity ? while [ ( length? check-ports ) > 0 ] [ conn: first check-ports ; Is port still active ? either query conn [ ; Port active ... so check if any data to be read either not ( none? ( wait [ 0 conn ] ) ) [ ; Yes .. so determine size of data to be read readbuffer: copy #{} readbuffer: copy conn ; If length is none? then connection has been closed either none? readbuffer [ ; Close down port and tidy up wait-ports block entry close conn remove check-ports ] [ ; Is this NOT a HTTP request ? either none? ( find readbuffer HTTP/1. ) [ ; Remove data from port clear conn ; Move onto next port check-ports: next check-ports ] [ ; HTTP request so detrmine what to do ... ; Remember it's a non-persistent connection ; Tidy up clear conn close conn ] ; VIP - empty out buffer area !!! clear readbuffer ] ; end of either none? readbuffer ] [ check-ports: next check-ports ] ] [ ; Port is no longer active ! ; tidy up clear conn close conn remove check-ports ] ; end of query conn ] ; end of while ( length? ... ] quit