in reply to Re^6: Check connection state prior to send data
in thread Check connection state prior to send data
Maybe it would be a good idea to check the return value of ->send? The following program behaves as I expect, telling me that the remote end has closed the connection:
#!/usr/bin/perl use IO::Socket; my $sock1; sub OpenSocket{ $sock1 = IO::Socket::INET->new( PeerAddr => '192.168.1.99', PeerPort => 80, Proto => 'tcp' ); $sock1 or die "no socket :$!"; } ################ START SCRIPT ################# OpenSocket(); $str="Something to send"; while (1) { if( !$sock1->send($str)) { warn "Error: $! / $^E"; }; } close($sock1);
I'm not sure if the autodie pragma also covers IO::Socket. If it does, maybe you want to use it, if not, you will have to check every function call you make yourself for success/failure.
|
|---|