[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 (Text):

    #!/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 (Text):

    #!/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. Advertisements

  2. Larry

    Uri Guttman Guest

    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, Dec 1, 2004
    #2
    1. Advertisements

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