Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hello jrtaylor, and welcome to the Monastery!

I can’t test your code, as Time::Out doesn’t work on Windows. But I’ve had a go at reducing your script to a minimum example (see How do I post a question effectively?):

#! perl use strict; use warnings; use IO::Socket; use Time::Out qw(timeout); $SIG{PIPE} = "IGNORE"; $| = 1; umask 002; my $socket = new IO::Socket::INET( PeerAddr => '192.168.173.9', PeerPort => 7001, Proto => 'tcp', Type => SOCK_STREAM, ) or die "Can't open socket: $@\n"; # Open the output file my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time); my $ymd = sprintf "%04d%02d%02d%02d%02d%02d", $year + 1900, $mon + 1, $mday, $hour, $min, $sec; my $file = "/var/flexshare/shares/logs/backup.$ymd.txt"; open(my $out, '>', $file) or die "Can't open file '$file' for writing: + $!"; $out->autoflush(1); # Send to the socket print $socket "\r\n\r\nP H 19\r\n"; # Read from the socket my $nb_secs = 10; while (my $line = <$socket>) { timeout $nb_secs => sub { my $count = 0; until ($count == 5) # Read the next xx lines { print $out $line; $socket->flush(); $count++; } }; if ($@) { $line = ""; } } close $out; close $socket;

As far as I can see, the code within timeout $nbsecs => sub { ... } does nothing but write the same $line to the output file 5 times, flushing the socket each time. Did you mean to put the while loop that reads from the socket into the timeout sub?

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Timeout not working while reading from socket. by Athanasius
in thread Timeout not working while reading from socket. by jrtaylor

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (8)
    As of 2014-04-17 10:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (444 votes), past polls