in reply to Check if Socket is alive before send

The IO::Socket::INET manual page states
DESCRIPTION
"IO::Socket::INET" provides an object interface to creating and using sockets in the AF_INET domain. It is built upon the IO::Socket interface and inherits all the methods defined by IO::Socket.

and IO::Socket provides the method connected():

connected
If the socket is in a connected state the peer address is returned. If the socket is not in a connected state then undef will be returned.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Check if Socket is alive before send ("connected")
by tye (Sage) on Nov 19, 2007 at 16:55 UTC

    I'm not sure 'connected' does what you think it does. It tells you whether the remote-side address has been bound to the socket such that you can send via the socket without specifying a destination address. It is unclear to me whether some action on the remote side would cause connected() to stop returning the address that the socket was (and probably still is) bound to.

    The way I would tell that the socket needs to be reconnected would be to note that I got an error when I tried to send.

    - tye