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; }

In reply to Re^2: perl only listen in 127.0.0.1 by Anonymous Monk
in thread perl only listen in 127.0.0.1 by vzunigam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.