in reply to Re^5: Fetching HTML Pages with Sockets
in thread Fetching HTML Pages with Sockets

You flushed after the wrong print. <SOCK> is blocking because the GET is never sent; it's stuck in a buffer. flush forces the buffer to be sent and emptied, so the web server can see the request and reply to it.

use Socket; sub connect_host { local *SOCK; my $remote = gethostbyname("football.fantasysports.yahoo.com") || die("Error resolving host name: $!\n"); my $proto = getprotobyname('tcp'); my $port = 80; my $remote_host = sockaddr_in($port, $remote); socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die("Error creating socket: $!\n"); connect(SOCK, $remote_host) or die("Error connecting to remote host: $!\n"); print SOCK "GET / HTTP/1.0\015\012\015\012"; flush(SOCK); local $/; # Read until end of file (as opposed to end of line). return scalar(<SOCK>); } sub flush { select($_[0]); my $t=$|; $|=1; $|=$t; } my $page = connect_host(); print($page);