in reply to Re: How can I test TCP socket status in Perl?
in thread How can I test TCP socket status in Perl?

Thank you in advance, i want AmStillConnected() to return undef if not connected. here is output when not connected. 'Can't call method "connected" on an undefined value at Untitled 9.pl line 27.' but works when i first connect and test the status for this reason it's incomplete.. am running this on Mac, thank you again

  • Comment on Re^2: How can I test TCP socket status in Perl?

Replies are listed 'Best First'.
Re^3: How can I test TCP socket status in Perl?
by tangent (Parson) on Jul 26, 2015 at 23:56 UTC
    If $sock is not defined you are not connected, so you should test for that as well:
    sub AmStillConnected { return unless defined $sock; return unless $sock->connected; return 1; }
      thank you this worked work me.
        This may 'work' but be aware that your call to connected() isn't really achieving anything. You should be testing the success or failure of each individual read/write to the socket anyway.

        If you have found all ready the solution to your question, please post the complete code. So other people will benefit in future.

        Seeking for Perl wisdom...on the process of learning...not there...yet!