You can retrieve the status of a socket using $sock(sockname).status which returns connecting when a connection is being established, and active when a connected has been established. It will also return $null if the socket has been disconnected, i.e. it is no longer open