next up previous contents
Next: Database Access: the DBI Up: Perl on the Web Previous: FTP: the Net::FTP module   Contents

Two-way Internet Connections: the Socket module

use Socket;

$where = $#ARGV >= 0 ? $ARGV[0] : "sfo";
 
$port = 3000;
$host = "rainmaker.wunderground.com";
 
$iaddr = inet_aton($host) || die "No host: $host";
$paddr = sockaddr_in($port,$iaddr);
 
$proto = getprotobyname('tcp');
socket(SOCK,PF_INET,SOCK_STREAM,$proto) || die "Socket: $!";
connect(SOCK,$paddr) || die "connect: $!";
 
# disable buffering to allow interactive conversation
select((select(SOCK),$| = 1)[0]);

$/ = "Press Return to continue:";
$str = <SOCK>;
     
print SOCK "\n";
 
$/ = "3 letter forecast city code-- ";
$str = <SOCK>;
 
print SOCK "$where+\n";
 
$/ = "CITY FORECAST MENU";
 
($str = <SOCK>) =~ s#\n.*$/##;
 
print $str;
 
$/ = "Selection:";
$str = <SOCK>;
print SOCK "x\n";



Phil Spector 2002-10-18