Problem with IO::Socket::INET and pop

J

Joe

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
 
B

Ben Morrow

# 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
 
A

A. Sinan Unur

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

Ben Morrow

A. Sinan Unur said:
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
 
J

Joe

Ben Morrow said:
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
 
J

Joe

A. Sinan Unur said:
IIRC, $@ is the relevant variable for socket errors.

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

Thanks,
Joe
 
A

A. Sinan Unur

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

Ben Morrow

A. Sinan Unur said:
<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
 
A

A. Sinan Unur

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

A. Sinan Unur

(e-mail address removed) (Joe) wrote in

are you sure $Port == 110 at this point?
....
....
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.
 
J

Joe

A. Sinan Unur said:
(e-mail address removed) (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
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top