I want to receive an XML packet using IO::Sockets. I have a script to do so but it cuts out sometimes causing the program to terminate. This is bad since it will be incorporated ino a much larger program. The script I have now is:
#! perl -slw use strict; use IO::Socket; use XML::Simple; $SIG{PIPE} = "IGNORE"; $\="\n"; my $img = '"http://updraft.unl.edu/~uas/uas/uas.png"'; my $post_time; my $test; my $xs = XML::Simple->new( RootName=>'Telemetry', XMLDecl => 1); my $check = 0; for (;;){ my $tele_client = IO::Socket::INET->new( 'localhost:12345' ) or pr +int $!; if ($tele_client){ while( <$tele_client>) { ################################# print "@@@ started @@@"; if ($tele_client){ print "*** Recv UA ***"; $tele_client->recv($test, 100000000); print $test; #UAS Functions: print "Reading in XML"; my $uasdata = $xs->XMLin($test); print "--- XML ---"; print Dumper($uasdata); if ("$uasdata->{VehicleID}" eq 'Velocity'){ #Open Placefile open UASPF,'>',"/home/uas/public_html/uas/uaspf.tx +t.bak" or die "Cannot Open File uavpf.txt.bak!"; #open UASPF,'>',"uaspf.txt.bak" or die "Cannot Ope +n File uavpf.txt.bak!"; &time; #print placefile elements print UASPF "Title: UAS GPS Position"; print UASPF "Threshold: 999"; print UASPF "RefreshSeconds: 2"; print UASPF "Iconfile: 1, 22, 21, 10, 14, $img\n"; print UASPF "Icon: $uasdata->{GPS}->{Latitude}, $u +asdata->{GPS}->{Longitude}, $uasdata->{GPS}->{Heading}, 1, 1, $post_t +ime Latitude: $uasdata->{GPS}->{Latitude} Longitude: $uasdata->{GPS}- +>{Longitude} Heading: $uasdata->{GPS}->{Heading} Speed: $uasdata->{Ai +rData}->{TrueAirSpeed} cm/s"; close UASPF; rename("/home/uas/public_html/uas/uaspf.txt.bak", +"/home/uas/public_html/uas/uaspf.txt") or die"Unable to replace: $!"; #rename("uaspf.txt.bak", "uaspf.txt") or die"Unabl +e to replace: $!"; print "*** UA Done ***"; } } } } print "SLEEP"; sleep 5; }
The program stops here: $tele_client->recv($test, 100000000); The only way I have thought to fix it is by increasing the size of the received data. Is there a better way to do this?

In reply to Receiving an XML packet using IO::Socket by deadpickle

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.