in reply to perl only listen in 127.0.0.1

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.

Replies are listed 'Best First'.
Re^2: perl only listen in 127.0.0.1
by Anonymous Monk on May 23, 2009 at 15:18 UTC

    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)

        Thank you so much, now my script run very well :)