[newbie] IO::Socket::INET

Discussion in 'Perl Misc' started by Larry, Dec 1, 2004.

  1. Larry

    Larry Guest

    Hello

    I've a question about perl socket

    I'm on MacOS9 running Macperl5.6,I'm connected to the internet via adsl
    lan (dynamic ip)

    Below the "server" code I've been working on:

    Code:
    #!/perl
    #
    # Server
    
    use strict;
    use warnings;
    use IO::Socket::INET;
    
    my $server = IO::Socket::INET->new(LocalPort => '6362',
    Type      => SOCK_STREAM,
    Reuse     => 1,
    Listen    => 1 ) || die "$!\n";
    
    while ( my $client = $server->accept() ) {
    
    print $client "The time is now: " . scalar(localtime(time())) . "\n";
    close $client;
    
    }
    
    close($server);
    
    It does work fine!

    Below the "Client" code I've uploaded on my netfirms host:

    Code:
    #!/perl
    #
    # Client
    
    use strict;
    use warnings;
    use IO::Socket::INET;
    use CGI::Carp "fatalsToBrowser";
    use CGI;
    
    my $q = new CGI();
    
    print $q->header();
    
    my $socket = IO::Socket::INET->new(PeerAddr => '80.116.244.30',
    PeerPort => '6362',
    Proto    => 'tcp') || die "Can't
    connect to: 80.116.244.30 on port: 6362 $!\n";
    
    print $socket "Hi server!\n";
    
    my $answer = <$socket>;
    print $answer;
    
    close($socket);
    
    Unfortunately when I run the script via browser I get this message: "no
    route to host" ... I don't presently know why!
    Far from it,when I run the code above on my Mac setting "PeerAddr" as
    "127.0.0.1" it works quite fine! (I manage to get the "The time is..."
    message from the "server" script!)

    Anyone can help me?

    ta
    Larry, Dec 1, 2004
    #1
    1. Advertising

  2. Larry

    Uri Guttman Guest

    >>>>> "L" == Larry <> writes:

    L> Unfortunately when I run the script via browser I get this message: "no
    L> route to host" ... I don't presently know why!
    L> Far from it,when I run the code above on my Mac setting "PeerAddr" as
    L> "127.0.0.1" it works quite fine! (I manage to get the "The time is..."
    L> message from the "server" script!)

    that isn't a perl problem. you have no route to that host/port from
    where you run the client. probably a firewall or something. maybe the
    server box isn't exposed to the net or it has a firewall disallowing
    incoming ports (i think osx has that). so check the network config stuff
    for the mac first.

    uri

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, Dec 1, 2004
    #2
    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. Rad
    Replies:
    0
    Views:
    546
  2. Aggro

    Re: INET socket programming questions

    Aggro, Jun 28, 2003, in forum: C Programming
    Replies:
    1
    Views:
    1,213
    Artemio
    Jun 29, 2003
  3. Sébastien Cottalorda

    Pb with IO::Socket::INET and recv

    Sébastien Cottalorda, Sep 5, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    257
    Sébastien Cottalorda
    Sep 16, 2003
  4. Kai Bleek
    Replies:
    7
    Views:
    350
    Kai Bleek
    Oct 31, 2003
  5. Joe
    Replies:
    10
    Views:
    275
Loading...

Share This Page