Does the server close the socket after the response is sent? My code assumed so. The following looks for </xml> instead.
# Receive response. my $read_buf = ""; my $response; for (;;) { my $rv = sysread($oSocket, $read_buf, 4096, length($read_buf)); die("Unable to read from the socket: $!\n") if not defined $rv; die("Premature end of data\n") if not $rv; if ($read_buf =~ s{(.*</xml>)}{}si) { $response = $1; last; } }

Tested. Both version work fine for me (although the first requires that the server closes the socket after sending the response).

I've read that recv shrinks to a smaller size if the last chunk of bytes is shorter than the specivfied size (4096 in this case), while sysread tries to read the specified size.

sysread is never guaranteed to return the number of bytes requested. When reading from a socket, it returns when LENGTH bytes are available and after each (non-empty?) packet received. And left-over bytes are returned by the next call to sysread.

By the way, Type => 'SOCK_STREAM' should be Type => SOCK_STREAM, and specifying both Type and Proto is redundant.


In reply to Re^3: No data received on client socket by ikegami
in thread No data received on client socket by rbi

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.