Ok, so I guess first off, I was confused about sockets. Maybe I need to start over and 
rethink how to do this.

What I am wanting to do, is from a webpage, run a tail command on another machine to 
read x amount of lines from a log file and print it on a web page. I thought the 
'best' way would be a socket, but it turns out that the client cannot recieve data 
from the server, if I am understanding this correctly.

Another question is, what is wrong with IO::Socket?? I am still very new at perl and 
would appreciate input on the pros/cons of using Socket as opposed to using 
IO::Socket. (I hope this doesnt turn into a 'pico is better than vi'-type argument 
:-D) Anyways, any input at all is appreciated. I'm going to start looking into other 
way to accomplish this task.

Dave Kettmann
NetLogic
636-561-0680

-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]
Sent: Friday, August 20, 2004 10:49 AM
To: Dave Kettmann
Cc: Perl List (E-mail)
Subject: Re: Problems with a socket script


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