Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Input of a Data Stream

by basicdez (Pilgrim)
on Oct 05, 2001 at 20:07 UTC ( [id://117032]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://117032]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found