in reply to Re^5: Check connection state prior to send data
in thread Check connection state prior to send data

Could you please tell me how intercept the error coming from socket? Because I tried, the following:
... OpenSocket(); sleep(5); $str="Something to send"; $sock1->send($str);
Then, during sleep I disconnect acting on server. When the application try to send the message, it exit from execution without print anything.

Replies are listed 'Best First'.
Re^7: Check connection state prior to send data
by Corion (Patriarch) on Sep 24, 2016 at 09:26 UTC

    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.