Hi,
I have an issue with socket programming, that is I can't read (even with sysread) the end of the data on a socket.
Here is the (very) simple code that shows the issue.
use strict; use IO::Socket; my $host = IO::Socket::INET->new ( PeerAddr=> 'www.smartadserver.com', PeerPort=> '80', Proto => "tcp", Type => SOCK_STREAM, ); print $host <<EOM; GET /call/pubj/445/3197/138/M/5249542624/target? HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicati +on/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdoc +ument, application/x-ms-xbap, application/x-ms-application, applicati +on/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, * +/* Accept-Language: fr UA-CPU: x86 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CL +R 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.2) Host: www.smartadserver.com Proxy-Connection: Keep-Alive EOM my $byte; while (sysread($host,$byte,1)==1) { print $byte; }
What I should see, along with the HTTP response is the HTML header, however, here is what I get on the screen.
HTTP/1.1 302 Object moved Date: Tue, 01 Jul 2008 20:08:00 GMT Server: Microsoft-IIS/6.0 P3P: CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo" pragma: no-cache cache-control: private Location: /def/def/showdef.asp Content-Length: 210 Content-Type: text/html Expires: Mon, 30 Jun 2008 20:08:00 GMT Set-Cookie: sasd=%24a%3D78t%3B%24cn%3DFR%5FA8%3B%24isp%3D102%3B%24qt%3 +D184%5F1338%5F12468t; path=/ Set-Cookie: pdomid=5; path=/ Set-Cookie: TestIfCookieP=ok; expires=Fri, 26-Nov-2010 23:00:00 GMT; d +omain=smartadserver.com; path=/ Set-Cookie: TestIfCookie=ok; domain=smartadserver.com; path=/ Set-Cookie: ASPSESSIONIDSCCSCBCA=HGFAJNDBEBFKPPGMPLNOOJBM; path=/ Cache-control: no-cache ****** Suprisingly, HTML DATA is missing here...*****
And tcpdump is indeed showing the HTML code, so it is really being sent ! On top of this, if I do this manually (i.e. open a telnet on port 80 on www.smartadserver.com and paste the same HTTP request that is contained in the perl programm, I get the full response (HTTP answer+HTML code)).
I am really puzzled, particularly because I paid attention (using sysread) to read on a per-byte basis to avoid the necessity of having an EOL at the end of the data.
I've spent already a complete day looking at this and I would appreciate any hints ;-).
Thanks
S.

In reply to Can't read end data out of a socket by CapitaineCaverne

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.