Problem with IO::Socket::INET and pop

Discussion in 'Perl Misc' started by Joe, Nov 12, 2003.

  1. Joe

    Joe Guest

    Hello -

    I wrote some Perl for a Web based e-mail client. The code worked fine
    for quite a while until recently when I get my error message show up
    all the time.

    Here is a snipped of the code:

    # Connect to the POP server using port 110
    $SocketHandle = IO::Socket::INET->new (Proto=>"tcp",
    PeerAddr=>$ServerName, PeerPort=>$Port);

    if (!$SocketHandle)
    # Customized Error Function
    Error("cannot connect to port <B>$Port</B> on <B>$ServerName</B>",


    The web hosting company keeps telling me that they didn't change
    anything and that they can connect fine via telnet ServerName 110.

    Was this code correct to begin with? Maybe I used some functionality
    that has been deprecated since? Is there a way to better debug and
    find out why !$SocketHandle is returned?

    Joe, Nov 12, 2003
    1. Advertisements

  2. Joe

    Ben Morrow Guest

    You need to include $! in the error message so you (and we) have a
    better idea of what's going wrong.

    Ben Morrow, Nov 12, 2003
    1. Advertisements

  3. IIRC, [email protected] is the relevant variable for socket errors.
    A. Sinan Unur, Nov 13, 2003
  4. Joe

    Ben Morrow Guest

    I don't think you do... there is nothing in perlvar or perlipc or
    IO::Socket (that I can find) that implies this. I think you may be
    thinking of

    | Additionally, if the "h_errno" variable is supported in C, its value
    | is returned via $? if any "gethost*()" function fails.

    from perlvar?

    Ben Morrow, Nov 13, 2003
  5. Joe

    Joe Guest

    For $! I get 'Bad file number' and for [email protected] 'IO::Socket::INET: Connection refused'

    Joe, Nov 13, 2003
  6. Joe

    Joe Guest

    For $! I get 'Bad file number' and for [email protected] 'IO::Socket::INET: Connection refused'

    Joe, Nov 13, 2003
  7. No. I am thinking of the output from the following:

    #! C:/Perl/bin/perl.exe

    use strict;
    use warnings;

    use IO::Socket::INET;

    my $connection = IO::Socket::INET->new(
    'LocalAddr' => 'schmocalhost',
    'LocalPort' => 50000,
    'Proto' => 'tcp',
    'ReuseAddr' => 1,
    'Blocking' => 1,
    ) or die "\$\!: $!\n\$\@: [email protected]\n";


    $!: Invalid argument
    [email protected]: IO::Socket::INET: Bad hostname 'schmocalhost'

    Now, which message is better?

    Also, check out

    A sample socket creation looks like:

    use IO::Socket::INET;
    my $connection = IO::Socket::INET->new(@parameters)
    or die "Cannot connect: [email protected]";

    The @parameters will be described in a moment. Note that the error comes
    back in [email protected], not $!. (Some have argued that this is a misdesign, either on
    Perl's part or on the author's part, but we're stuck with the
    inconsistency either way.)

    A. Sinan Unur, Nov 13, 2003
  8. Joe

    Ben Morrow Guest

    I didn't know about that... thank you.

    Am I correct that this is not mentioned in the standard docs, or am I
    simply stupid... :) ?

    Ben Morrow, Nov 13, 2003
  9. It is in the IO::Socket::INET examples but I haven't seen it mentioned
    elsewhere. And, I remember being confused about the meaningless error
    messages printed by my programs when I was using $!.


    A. Sinan Unur, Nov 13, 2003
  10. (Joe) wrote in

    are you sure $Port == 110 at this point?
    That means your script could not connect to $ServerName on that port.
    Could it be a firewall issue? This does not seem to have much to do with

    A. Sinan Unur, Nov 13, 2003
  11. Joe

    Joe Guest

    Yeah ... it used to work with port 110 for the POP server.

    The thing is that Outlook can connect fine and it is using the same
    protocol and port to connect to that server.

    I do sit behind a firewall but if the machine on which the script runs
    does not have a firewall there should not be a problem ... right?
    Maybe I'm wrong and even if the page that calls the script is behind a
    firewall there is a problem.

    Joe, Nov 17, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.