On Aug 20, Dave Kettmann said:

>I am writing a socket script so I can pull a log file thru a web page.
>For right now, Im just trying to get it to work from a shell. I have
>gotten it to where the client sends information to the server, but this
>should work the other way. When I try to get the server to write to the
>client, I get a broken pipe error. Below is the code for the server
>program:

It looks like you have something backwards...

>my $sock = new IO::Socket::INET(
>        LocalHost => 'druidia.netlogic.net',
>        LocalPort => 7890,
>        Proto     => 'tcp',
>        Listen    => SOMAXCONN,
>        Reuse     => 1);

THIS is your LISTENING socket.  It makes no sense for YOU to print to it,
like you do later.

>$sock or die "no socket :$!";
>my($new_sock, $c_addr, $buf);
>
>while (($new_sock, $c_addr) = $sock->accept())
>{
> my ($client_port, $c_ip) =sockaddr_in($c_addr);
> my $client_ipnum = inet_ntoa($c_ip);
> my $client_host =gethostbyaddr($c_ip, AF_INET);

Eww.  You're using IO::Socket, so *use* it:

  while (my $client = $sock->accept) {
    my ($port, $host) = ($client->peerport, $client->peerhost);
    # do whatever logging you want with those values...
    print $client tail(-75, "/var/log/radius.log");
    close $client;  # not strictly necessary, due to scoping
  }

-- 
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to