Newbie dot Org
Code Snippets
CGI
You definitely should use something more advanced then this for a real application. This little snippet could defintely use some better error checking, etc. But it should demonstrate how to use Perl's IO::Socket interface without cluttering it up to much. #!/usr/bin/perl -w use IO::Socket;
$server = 'www.newbie.org'; $port = 80; $socket = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $server, PeerPort => $port, Timeout => 10, ); unless($socket) { die("Could not connect to $server:$port"); } $socket->autoflush(1); print $socket ("GET / HTTP/1.0\nHost: $server\nReferer: http://www.newbie.org\nUser-Agent: Simple Socket 1.2b\n\n"); $off = 1; while ($line = <$socket>) { if ($line =~ /^\s*$/) { $off = 0; } unless ($off) { print($line); } } exit();
Posted by Jake on 04/03/00 at 22:27:04
|