http://www.perlmonks.org?node_id=170324

bufo has asked for the wisdom of the Perl Monks concerning the following question:

I have an application which sends and receives messages down a number of sockets. If I call send to a socket where the pc on which I need to send the message to has crashed and is re-booting then the program crashes out. Is there any way in which I can check the status of the socket or remote machine before doing the send?

Originally posted as a Categorized Question.

  • Comment on Checking if remote exists before calling send

Replies are listed 'Best First'.
Re: Checking if remote exists before calling send
by rasta (Hermit) on Oct 10, 2002 at 07:24 UTC
    I can advice you two solutions:

    1. Use SO_KEEPALIVE socket option like in the following example:
    use IO::Socket; my $sock = IO::Socket::INET->new('some_server'); $sock->read(1024,$data) until $sock->atmark;
    2. You may use NetPacket::ICMP to check if remote host is alive.