REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Ports: Reading from a Port

Pending Revision

This document was written for R2 and has yet to be revised for R3.

The series copy function is used to read data from an open port:

print copy fp
I wanted the gold, and I sought it,I scrabbled and mucked like
a slave....

This function will wait for the port data. If you don't want to wait for the data, open the port with the /no-wait refinement.

To read only a portion of the port data, use copy/part:

print copy/part fp 35
I wanted the gold, and I sought it,

Note that the second argument to copy can be a length or a position within the port.

You can use the series find and copy functions to read just part of the port's data:

a: find fp "famine"
print copy/part a find a newline
famine or scurvy -- I fought it;

The first, next, and other positional series functions can also be used on the port:

print first fp
I
print first next next fp
w

The copy function will return none! when all data have been read from a port. When running in /no-wait mode, the copy function will return an empty string if no data is available for the port.

tp: open/direct/binary/no-wait tcp://system:8000
content: make binary! 1000
while [wait tp  data: copy tp] [append content data]
close tp


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin