basicdez has asked for the wisdom of the Perl Monks concerning the following question:

Okay. Please offer first forgiveness for my lack of knowledge, but here goes with my question. I need to read in a data stream that will be coming through a Port from another software package. I know the ending of the data stream is when "EOS" "EOS" is found. This is what I have so far, but I am sure that I am barely close. Please help me if you can... thanks dez L
my $clientfd = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => "tcp", Type => SOCK_STREAM); if ($@) { my $conn_err = "Could not connect to $host:$port:$@"; }
Okay, I think that is what I have to do open my port, but now what do I need to do to read in the incoming data stream coming from $host:$port. Please help if you can.

Replies are listed 'Best First'.
Re: Input of a Data Stream
by gbarr (Monk) on Oct 05, 2001 at 21:24 UTC
    In order to give a full response we would need to know more. Is the data you are reading line based ? Does the app need to read from more than one connection at a time ?

    Depending on what your answers are will change how many short-cuts you can take.

    If this is just a simple app that reads a line based datastream from just the one socket then you can do

    while(<$clientfd>) { last if /^EOS$/; # process line } close($clientfd);

    But if you want to read from more than one socket at a time then you will need to use sysread and select

Re: Input of a Data Stream
by chromatic (Archbishop) on Oct 05, 2001 at 21:12 UTC
    You can read from your socket as you would a normal filehandle. You could use read to read from it as well. Filehandle-type reads are easier, but if you're looking for a specific end of message sequence, you're better off going with read.

    See perlipc for more details.