I'm in the process of writing my first script that makes use of sockets and it's SLOW. All it does is connect to a webserver, login if necessary and fetch the requested page.
The point was to stop using $somevar = system('lynx -dump http://thesite.com'); because of the unnecessary overhead of calling lynx to make a simple GET request. Unfortunatly it seems like lynx is actually faster! Am I doing something dumb here that's causing this?
my $server = "theSite.com"; my $proto = getprotobyname("tcp") || 6; my $port = getservbyname("http", "tcp") || 80; my $packed_remote_ip = inet_aton($server); my $s_server = sockaddr_in($port, $packed_remote_ip); $req1="GET /board/ HTTP/1.0\r\n"; $req1 .= "Host: $server\r\n"; $req1 .= "Accept: text/html, text/plain, text/css, text/sgml, */*; +q=0.01\r\n"; $req1 .= "Accept-Language: en\r\n"; $req1 .= "User-Agent: Lynx/2.8.6rel.4 libwww-FM/2.14 SSL-MM/1.4.1 +OpenSSL/0.9.8i\r\n"; $req1 .= 'Cookie2: $Version="1"' . "\r\n"; # I have no idea what t +his is for but lynx sends it so.. so am I! $req1 .= "\r\n"; socket(SK_CLIENT, PF_INET, SOCK_STREAM, $proto) || die("Socket Err +or req1: $! \n"); connect(SK_CLIENT,$s_server) || die("Connect Error: $! \n"); send(SK_CLIENT,$req1,0) || print "send error: $! \n"; $data = 1; while ($data) { recv(SK_CLIENT, $data, 100, 0); $thePage .= $data; } close SK_CLIENT || die("Close error: $!"); print "$thePage\n";
In reply to My first socket program is SLOW? by ttlgreen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |