Greetings perl monks!

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.