Telnet, XML API, and I/O Buffering

Greetings, again, O Wise Monks. I have a bit of an issue in dealing with an API that uses XML to drive it, and I know that there has to be a (relatively) simple way to do what I'm attempting. All the pertinent details are below:

Problem: Need to use the API of an aplication to get a list of items in its internal database.

facts:

Analysis:

What I have so far is two different ways to approach this:

The problem that I am running into is, if I use print and read, the interactivity with the application suffers, and I can't seem to get it to recognize that I sent it a request, so my script just hangs.

Likewise, if I use sysread/syswrite, I get the interactivity, and get some of the output, but the XML::LibXML parser dies because I don't capture all of the output...

Code snippets:

This is what I'm working with:
my $NODEREC = " <XML REQUEST RECORD GOES HERE> " my $sok = IO::Socket::INET->new(PeerAddr => $WYSHOST, PeerPort => $WYSPORT, Proto => "tcp") or die "couldn't connect to WysDM host $WYSHOST : $!\n"; #$sok->autoflush(1); $| = 1; my $parser = XML::LibXML->new;
From there, the two options I have tried are:
print $sok "$NODEREC\n"; while ($line = <$sok>){ print "reading line\n"; chomp($line); push(@output, $line); }
or, using sysread
syswrite $sok, $NODEREC; syswrite $sok, "\n"; my $blksize = (stat $sok)[11] || 16384; my $len = sysread $sok, $res, $blksize; my $ds = $parser->parse_string("$res");

What recommendations can ou give me on the optimal way to perform this task?

Many Thanks in Advance

In reply to Telnet, XML API, and I/O Buffering by BluePerlDev

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.