http://www.perlmonks.org?node_id=6966

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

How do I get started (reading data from a socket)

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I get started (reading data from a socket)
by marcos (Scribe) on May 02, 2000 at 15:03 UTC
    I use the <> operator to read data from a socket:
    use strict; use IO::Socket; my $host = 'myhost.mysite.org'; my $port = 7530; my $sock = new IO::Socket::INET(PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); die "cannot open socket" unless ($sock); #send a command to the server my $cmd = "MYGET\n"; print $sock $cmd; # print server response while (<$sock>) { print; } close $sock;

    marcos
Re: How do I get started (reading data from a socket)
by Anonymous Monk on Jul 13, 2001 at 18:28 UTC
    Answer: I'am clear about u r context,but i would like to give my feedback on this: If u want to read data from a socket, better check the socket whether it is ready for reading (means has it got any data to read ????, then start reading, otherwise the read calls may turn out to be blocking calls) i beleive u have select() fun to check whether a socket is ready to receive,use it , confirm , start reading --------Fhani

    Originally posted as a Categorized Answer.