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>",
    "Back");

    exit(0);
    }

    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?

    Thanks,
    Joe
     
    Joe, Nov 12, 2003
    #1
    1. Advertising

  2. Joe

    Ben Morrow Guest

    (Joe) wrote:
    > # 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>",
    > "Back");
    >
    > exit(0);
    > }
    >
    > 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?


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

    Ben

    --
    I've seen things you people wouldn't believe: attack ships on fire off the
    shoulder of Orion; I've watched C-beams glitter in the darkness near the
    Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
    Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
     
    Ben Morrow, Nov 12, 2003
    #2
    1. Advertising

  3. Ben Morrow <> wrote in news:boueo5$9cp$1
    @wisteria.csv.warwick.ac.uk:

    >
    > (Joe) wrote:
    >
    >> # Customized Error Function
    >> Error("cannot connect to port <B>$Port</B> on <B>$ServerName</B>",
    >> "Back");

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


    IIRC, $@ is the relevant variable for socket errors.

    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Nov 13, 2003
    #3
  4. Joe

    Ben Morrow Guest

    "A. Sinan Unur" <> wrote:
    > IIRC, $@ is the relevant variable for socket errors.


    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

    --
    For the last month, a large number of PSNs in the Arpa[Inter-]net have been
    reporting symptoms of congestion ... These reports have been accompanied by an
    increasing number of user complaints ... As of June,... the Arpanet contained
    47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] *
     
    Ben Morrow, Nov 13, 2003
    #4
  5. Joe

    Joe Guest

    Ben Morrow <> wrote in message news:<boueo5$9cp$>...
    > (Joe) wrote:
    > > # 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>",
    > > "Back");
    > >
    > > exit(0);
    > > }
    > >
    > > 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?

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


    For $! I get 'Bad file number' and for $@ 'IO::Socket::INET: Connection refused'

    Thanks,
    Joe
     
    Joe, Nov 13, 2003
    #5
  6. Joe

    Joe Guest

    "A. Sinan Unur" <> wrote in message news:<Xns9431E16F41CF4asu1cornelledu@132.236.56.8>...
    > Ben Morrow <> wrote in news:boueo5$9cp$1
    > @wisteria.csv.warwick.ac.uk:
    >
    > >
    > > (Joe) wrote:
    > >
    > >> # Customized Error Function
    > >> Error("cannot connect to port <B>$Port</B> on <B>$ServerName</B>",
    > >> "Back");

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

    >
    > IIRC, $@ is the relevant variable for socket errors.


    For $! I get 'Bad file number' and for $@ 'IO::Socket::INET: Connection refused'

    Thanks,
    Joe
     
    Joe, Nov 13, 2003
    #6
  7. Ben Morrow <> wrote in news:bovrgs$qb3$3
    @wisteria.csv.warwick.ac.uk:

    >
    > "A. Sinan Unur" <> wrote:
    >> IIRC, $@ is the relevant variable for socket errors.

    >
    > 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?


    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\$\@: $@\n";

    __END__

    C:\temp> d.pl
    $!: Invalid argument
    $@: IO::Socket::INET: Bad hostname 'schmocalhost'

    Now, which message is better?

    Also, check out http://www.stonehenge.com/merlyn/UnixReview/col47.html:

    <blockquote>
    A sample socket creation looks like:

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

    The @parameters will be described in a moment. Note that the error comes
    back in $@, 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.)
    </blockquote>

    Sinan.
    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Nov 13, 2003
    #7
  8. Joe

    Ben Morrow Guest

    "A. Sinan Unur" <> wrote:
    > <blockquote>
    > A sample socket creation looks like:
    >
    > use IO::Socket::INET;
    > my $connection = IO::Socket::INET->new(@parameters)
    > or die "Cannot connect: $@";
    >
    > The @parameters will be described in a moment. Note that the error comes
    > back in $@, 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.)
    > </blockquote>


    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

    --
    . | .
    \ / The clueometer is reading zero.
    . .
    __ <-----@ __
     
    Ben Morrow, Nov 13, 2003
    #8
  9. Ben Morrow <> wrote in
    news:bp0jvq$a1k$:

    >
    > "A. Sinan Unur" <> wrote:
    >> <blockquote>
    >> A sample socket creation looks like:
    >>
    >> use IO::Socket::INET;
    >> my $connection = IO::Socket::INET->new(@parameters)
    >> or die "Cannot connect: $@";
    >>
    >> The @parameters will be described in a moment. Note that the error
    >> comes back in $@, 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.)
    >> </blockquote>

    >
    > 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... :) ?


    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 $!.

    HTH.

    Sinan.
    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Nov 13, 2003
    #9
  10. (Joe) wrote in
    news::

    > Ben Morrow <> wrote in message
    > news:<boueo5$9cp$>...
    >> (Joe) wrote:
    >> > # Connect to the POP server using port 110
    >> > $SocketHandle = IO::Socket::INET->new (Proto=>"tcp",
    >> > PeerAddr=>$ServerName, PeerPort=>$Port);


    are you sure $Port == 110 at this point?
    ....

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

    ....
    > For $! I get 'Bad file number' and for $@ 'IO::Socket::INET:
    > Connection refused'


    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
    Perl.

    Sinan.

    --
    A. Sinan Unur

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Nov 13, 2003
    #10
  11. Joe

    Joe Guest

    "A. Sinan Unur" <> wrote in message news:<Xns9432BF749A82asu1cornelledu@132.236.56.8>...
    > (Joe) wrote in
    > news::
    >
    > > Ben Morrow <> wrote in message
    > > news:<boueo5$9cp$>...
    > >> (Joe) wrote:
    > >> > # Connect to the POP server using port 110
    > >> > $SocketHandle = IO::Socket::INET->new (Proto=>"tcp",
    > >> > PeerAddr=>$ServerName, PeerPort=>$Port);

    >
    > are you sure $Port == 110 at this point?
    > ...
    >
    > >> > The web hosting company keeps telling me that they didn't change
    > >> > anything and that they can connect fine via telnet ServerName 110.

    > ...
    > > For $! I get 'Bad file number' and for $@ 'IO::Socket::INET:
    > > Connection refused'

    >
    > 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
    > Perl.
    >
    > Sinan.


    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.

    Thanks,
    Joe
     
    Joe, Nov 17, 2003
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sébastien Cottalorda

    Pb with IO::Socket::INET and recv

    Sébastien Cottalorda, Sep 5, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    280
    Sébastien Cottalorda
    Sep 16, 2003
  2. Hobbit HK

    IO::Socket::INET Problem

    Hobbit HK, Feb 9, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    186
    Hobbit HK
    Feb 12, 2004
  3. Lucas Young

    Problem with Perl DBI - IO::Socket::INET:

    Lucas Young, Dec 11, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    515
    Lucas Young
    Dec 14, 2005
  4. DJ Stunks
    Replies:
    11
    Views:
    498
  5. Stuart Gall

    IO::Socket::INET on OSX or TCP stack problem

    Stuart Gall, May 7, 2009, in forum: Perl Misc
    Replies:
    17
    Views:
    408
    Stuart Gall
    May 15, 2009
Loading...

Share This Page