BluePerlDev has asked for the wisdom of the Perl Monks concerning the following question:
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:From there, the two options I have tried are: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;
or, using sysreadprint $sok "$NODEREC\n"; while ($line = <$sok>){ print "reading line\n"; chomp($line); push(@output, $line); }
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Telnet, XML API, and I/O Buffering
by ikegami (Patriarch) on Jul 27, 2010 at 19:49 UTC | |
|
Re: Telnet, XML API, and I/O Buffering
by ivo_ac (Acolyte) on Jul 27, 2010 at 20:31 UTC | |
by BluePerlDev (Novice) on Jul 29, 2010 at 19:48 UTC | |
by ivo_ac (Acolyte) on Jul 30, 2010 at 20:30 UTC |