Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^6: Check connection state prior to send data

by Lucas Rey (Sexton)
on Sep 24, 2016 at 09:16 UTC ( [id://1172531]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found