Dear Monks,
I am trying to write a script that will perform an HTTP get and analyze the server response.
This should be done in a loop and for performance I would like to create the socket to the server only once and perform the GET on the open socket.
When running my script the socket gets closed and I get an error. Only if I open a new socket, which makes me perform the – syn, syn-ack, ack – all over again, am I able to perform the GET.
How can I accomplish this with one socket?
This is the main script:

#!/usr/bin/perl -w use IO::Socket; use Encode; use utf8; unless (@ARGV > 0) { die "usage: host ..." } $host = shift(@ARGV); $EOL = "\015\012"; $BLANK = $EOL x 2; $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => "http(80)", ); unless ($remote) { die "cannot connect to http daemon on $host" } $remote->autoflush(1); while (1) { $msg = "GET /engine3.php?req_sale=5205&page=1\r\n"; $remote->send($msg); while ( <$remote> ) { $temp .= $_; } utf8::encode($temp); print "$temp\n"; undef($temp); sleep(2); # close $remote; }
Regards,
Adi.

In reply to IO::Socket, Multiple GET. by adismaug

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.