Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Problem with IO::Socket::INET and pop (http://www.velocityreviews.com/forums/t883613-problem-with-io-socket-inet-and-pop.html)

Joe 11-12-2003 10:57 PM

Problem with IO::Socket::INET and pop
 
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

Ben Morrow 11-12-2003 11:12 PM

Re: Problem with IO::Socket::INET and pop
 

unixverse@yahoo.com (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.me.uk

A. Sinan Unur 11-13-2003 03:09 AM

Re: Problem with IO::Socket::INET and pop
 
Ben Morrow <usenet@morrow.me.uk> wrote in news:boueo5$9cp$1
@wisteria.csv.warwick.ac.uk:

>
> unixverse@yahoo.com (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
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov

Ben Morrow 11-13-2003 11:56 AM

Re: Problem with IO::Socket::INET and pop
 

"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> 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.me.uk

Joe 11-13-2003 01:26 PM

Re: Problem with IO::Socket::INET and pop
 
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<boueo5$9cp$1@wisteria.csv.warwick.ac.uk>...
> unixverse@yahoo.com (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 11-13-2003 01:27 PM

Re: Problem with IO::Socket::INET and pop
 
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns9431E16F41CF4asu1cornelledu@132.236.56.8> ...
> Ben Morrow <usenet@morrow.me.uk> wrote in news:boueo5$9cp$1
> @wisteria.csv.warwick.ac.uk:
>
> >
> > unixverse@yahoo.com (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

A. Sinan Unur 11-13-2003 05:23 PM

Re: Problem with IO::Socket::INET and pop
 
Ben Morrow <usenet@morrow.me.uk> wrote in news:bovrgs$qb3$3
@wisteria.csv.warwick.ac.uk:

>
> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> 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
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov

Ben Morrow 11-13-2003 06:53 PM

Re: Problem with IO::Socket::INET and pop
 

"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> 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.me.uk

A. Sinan Unur 11-13-2003 07:54 PM

Re: Problem with IO::Socket::INET and pop
 
Ben Morrow <usenet@morrow.me.uk> wrote in
news:bp0jvq$a1k$1@wisteria.csv.warwick.ac.uk:

>
> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> 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
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov

A. Sinan Unur 11-13-2003 11:49 PM

Re: Problem with IO::Socket::INET and pop
 
unixverse@yahoo.com (Joe) wrote in
news:fcc97b00.0311130526.fe5e615@posting.google.co m:

> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<boueo5$9cp$1@wisteria.csv.warwick.ac.uk>...
>> unixverse@yahoo.com (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
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


All times are GMT. The time now is 07:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57