Example 8-2. examples/network/io_socket.pl
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket;
# IO::Socket is a higher level abstraction
# Hides many of the ugly part we had to know in case of the socket() function.
# Provides an OOP interface.
#my $host = '127.0.0.1';
my $host = 'localhost';
#my $host = 'www.google.com';
#my $host = '209.85.135.103';
#my $host = 'www.perl.org.il';
my $port = 80;
my $CRLF = "\015\012";
my $socket = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
) or die $!;
$socket->send("GET /$CRLF") or die $!;
my $SIZE = 100;
my $data = '';
while ($socket->read($data, $SIZE, length $data) == $SIZE) {};
print $data;| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Socket level programming using Socket.pm | Up | Newline |