LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perldoc perlipc example fails, debian 4 (https://www.linuxquestions.org/questions/programming-9/perldoc-perlipc-example-fails-debian-4-a-511086/)

eerok 12-16-2006 10:49 AM

perldoc perlipc example fails, debian 4
 
I'm just curious why this example from the perl docs doesn't work. The service of course exists in /etc/services. I edited the code trivially to use warnings and strict, I read 'perldoc IO::Socket::INET', I've tried several variations, but it doesn't work no matter what I tried:
Code:

#!/usr/bin/perl
# local-001 - example from perlipc (perl 5.8.8)
use strict;
use warnings;
use IO::Socket::INET;

my $remote = IO::Socket::INET->new (
    Proto    => "tcp",
    PeerAddr => "localhost",
    PeerPort => "daytime(13)",
    )
    or die "cannot connect to daytime port at localhost";
while (<$remote>) {print}

tale@hyute:~/00-perl$ ./local-001
cannot connect to daytime port at localhost at ./local-001 line 7.

It's not a big deal, however it helps when you're learning a language to be rigorous about why things fail ... and I'm just learning perl. I think there's a system-related reason why I can't access that socket ...

mcummings 12-17-2006 08:07 AM

unless you're running a daytime service (like ntp) locally and it's bound to localhost, this is bound to fail. On the upside, the fact that you get the "cannot connect to daytime port" means that it in fact did attempt to establish a socket call. Not so much a bad example as much as a poorly thought out one (depends too much on you having a particular service running).

eerok 12-17-2006 11:03 AM

Ah, I thought it would be something like that. I also thought that I had ntp running, but since I've rebuilt the system lately, maybe I don't :)

In a sideways fashion, maybe it wasn't such a bad example, because now I know more about IO::Socket::INET than I would've if the example had succeeded right away.


All times are GMT -5. The time now is 05:51 PM.