Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problem with IO::Socket::INET and pop

Reply
Thread Tools

Problem with IO::Socket::INET and pop

 
 
Joe
Guest
Posts: n/a
 
      11-12-2003
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
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      11-12-2003

http://www.velocityreviews.com/forums/(E-Mail Removed) (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. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| (E-Mail Removed)
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-13-2003
Ben Morrow <(E-Mail Removed)> wrote in news:boueo5$9cp$1
@wisteria.csv.warwick.ac.uk:

>
> (E-Mail Removed) (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
(E-Mail Removed)
Remove dashes for address
Spam bait: (E-Mail Removed)
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-13-2003

"A. Sinan Unur" <(E-Mail Removed)> 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] * (E-Mail Removed)
 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      11-13-2003
Ben Morrow <(E-Mail Removed)> wrote in message news:<boueo5$9cp$(E-Mail Removed)>...
> (E-Mail Removed) (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
 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      11-13-2003
"A. Sinan Unur" <(E-Mail Removed)> wrote in message news:<Xns9431E16F41CF4asu1cornelledu@132.236.56.8> ...
> Ben Morrow <(E-Mail Removed)> wrote in news:boueo5$9cp$1
> @wisteria.csv.warwick.ac.uk:
>
> >
> > (E-Mail Removed) (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
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-13-2003
Ben Morrow <(E-Mail Removed)> wrote in news:bovrgs$qb3$3
@wisteria.csv.warwick.ac.uk:

>
> "A. Sinan Unur" <(E-Mail Removed)> 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
(E-Mail Removed)
Remove dashes for address
Spam bait: (E-Mail Removed)
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-13-2003

"A. Sinan Unur" <(E-Mail Removed)> 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.
. .
__ <-----@ __ (E-Mail Removed)
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-13-2003
Ben Morrow <(E-Mail Removed)> wrote in
news:bp0jvq$a1k$(E-Mail Removed):

>
> "A. Sinan Unur" <(E-Mail Removed)> 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
(E-Mail Removed)
Remove dashes for address
Spam bait: (E-Mail Removed)
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-13-2003
(E-Mail Removed) (Joe) wrote in
news:(E-Mail Removed) m:

> Ben Morrow <(E-Mail Removed)> wrote in message
> news:<boueo5$9cp$(E-Mail Removed)>...
>> (E-Mail Removed) (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
(E-Mail Removed)
Remove dashes for address
Spam bait: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are "Array#push" and "pop" not "push!" and "pop!"? samppi Ruby 27 12-05-2007 07:24 AM
How to do server-side processing and then display pop-up with pop-up blocker enabled domtam@hotmail.com ASP .Net 2 02-04-2006 06:03 PM
How to do server-side processing and then display pop-up with pop-up blocker enabled domtam@hotmail.com Javascript 2 02-04-2006 06:03 PM
pop up prevention problem; for wanted pop ups joe doe Firefox 2 03-03-2005 08:08 AM
Pop-up to Buy Pop-up software William Young Computer Support 4 01-24-2004 12:28 AM



Advertisments