in reply to syswrite, closed socket and error handling
at the top of your script it won't die/exit silently. or you could do$SIG{PIPE} = 'IGNORE';
By no means optimal at all, but just to give you an idea.my $connected = 0; $SIG{PIPE} = sub { warn "Lost connection to server: $!"; $connected = +0; }; use IO::Socket::INET; use Carp; sub new_connection { return IO::Socket::INET->new( PeerAddr=> $host, PeerPort=> $port, Proto=> "tcp", Blocking => 1 ) ; } my $socket = new_connection() or die "$!"; my $output; for(1..100){ print $_ . ".."; sleep(2); if ($connected) { $output = $socket->syswrite($string); } else { $socket = new_connection (); or die "$!" $connected = 1; } print "done\n"; }
|
|---|