Some good answers already and pg hinted at part of the problem.

Your loop will not end until end-of-file. Once you get end-of-file, you can't get more data.

A second part of the problem is that you are specifying HTTP v1.0 which doesn't support multiple requests per connection. If you specify HTTP v1.1, then you could to multiple requests per connection but you'll have to change your loop to not go all the way to end-of-file. You may also need to not use the read-line operator (<$sock>) since it will wait forever looking for a record separator and I'm not certain that HTTP v1.1 responses are guaranteed to end in a newline.

If you really want to do this, then you'll need to learn the HTTP v1.1 protocol. You can look at how LWP does this as one step in that process. Searching for "1.1" I found that LWP/Protocol/http.pm has some of the code that handles this. A simple google search, http 1.1 standard, will find you the full details of the HTTP v1.1 protocol.

Or you could just use a module that has already done all of this work for you as several others have already suggested.

                - tye

In reply to Re: socket won't let me fetch multiple web pages (HTTP v1.1) by tye
in thread socket won't let me fetch multiple web pages by Anonymous Monk

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.