vzunigam has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i want to config my PERL script to listen out the localhost in the 777 port number, but i dont know how i can change this behavior. When i put this command: netstat -plant | grep 777

appears this:

tcp 0 0 127.0.0.1:777 0.0.0.0:* ESCUCHAR 3240/perl

So if you see PERL only listen in the localhost. Finally the question is, how i change the PERL to listen out of the localhost?

Thanks you for help

PD:I Use Ubuntu 9

Replies are listed 'Best First'.
Re: perl only listen in 127.0.0.1
by ig (Vicar) on May 23, 2009 at 04:47 UTC

    The way to set the port is different depending on what function or module you are using to open the port. If you post your code, showing how you are opening the port, someone may be able to help you.

    In the mean time, you might have a look at perlipc. This documentation includes example servers that listen on specific ports.

      This is the server code.

      To run i use: perl server.pl 777

      use strict; use IO::Socket; #tomar el puerto a controlar o por default 777 my $port = $ARGV[0] || 777; #Variables para la configuracion del servidor remoto a quien pasarle #los parametros del GPS my $remotehost = $ARGV[1] || "localhost"; my $remotepag = $ARGV[2] || "/puntogps.php"; my $rcvdata; #ignorar procesos hijos para evitar zombies $SIG{CHLD} = 'IGNORE'; #crear el socket a escuchar my $listen_socket = IO::Socket::INET->new(LocalPort => $port, LocalAddr => 'localhost', Listen => 1000, Proto => 'tcp', Reuse => 1); #asegurarnos que estamos controlando el puerto die "Cant't create a listening socket: $@" unless $listen_socket; warn "Server ready. Waiting for connections ...", $port, "\n"; #esperar conexiones while (my $connection = $listen_socket->accept){ my $child; # crear el fork para salir die "Can't fork: $!" unless defined ($child = fork()); #¡el hijo! if ($child == 0){ #cerrar el puerto para escuchar el proceso hijo $listen_socket->close; #llamar a la funcion que hace el request al servicio web $rcvdata = <$connection>; callws($remotehost, $remotepag, $rcvdata); #si el hijo regresa salte exit 0; } #¡soy el padre! else{ #¿quién se conectó? warn "Connecton received ... ",$connection->peerhost,"\n"; #cerrar la conexión, ya fue mandada a un hijo $connection->close(); } #regresa a escuchar otras conexiones } sub callws{ my $rh = shift; my $rp = shift; my $rd = shift; my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $rh, PeerPort => "http(80)" ); unless ($remote) { die "cannot connect to http daemon on $rh" } $remote->autoflush(1); print $remote "GET $rp HTTP/1.0\n\n"; while ( <$remote> ) { print } close $remote; }
        Your specification:
        my $listen_socket = IO::Socket::INET->new(LocalPort => $port, LocalAddr => 'localhost', # <<<<<<<<< H E R E <<<<<<<< Listen => 1000, Proto => 'tcp',
        Tells the server to bind to the localhost.

        Simply remove or comment out the line, and it will bind to all interfaces.

             Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)