Need help with Client/Server script using IO::Socket & File::Tail 
Author Message
 Need help with Client/Server script using IO::Socket & File::Tail

Quote:
>From a Sun box I want to connect to another Sun box and actively view a

log file like the Unix 'tail -f' command.  I have written a Perl server
script (see listing below) that allows connections from a client and
immediately starts the 'tail -f' on the log file.  This part works
fine.  Now, from the client machine, I would like to write a Perl
script that connects to the server and has the ability to start and
stop the 'tail -f' on the server while still keeping the connection.  I
know the client script to connect to the server is simple to write, I
just need help getting the ability to start|stop the tail'ing while
keeping the connection.
Any help with this would be greatly appreciated.  I have searched many
sites for scripts that use both IO::Socket and File::Tail modules but
have been unsuccessful.
The script listed below is the server side that allows the connection
and does the 'tail -f'.

-----
#!/usr/local/bin/perl5 -w
#
use strict;
use IO::Socket;
use Net::hostent;
use File::Tail;

my $name="/some/log/file";
my($client, $line, $hostinfo, $file);
my($SERVERPORT, $server);

my $SERVERPORT = 9000;
my $server = IO::Socket::INET->new(
                                Proto     => 'tcp',
                                LocalPort => $SERVERPORT,
                                Listen    => 10,
                                Reuse     => 1,
                                )

print "[Server $0 accepting clients]\n";

while ($client = $server->accept())
{
  $client->autoflush(1);
  print $client "Welcome to $0; type help for command list.\n";
  $hostinfo = gethostbyaddr($client->peeraddr);
  printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost;

  $file=File::Tail->new(name => $name);

  while ($line=$file->read)
  {
    print $client "$line";
  }
  close $client;

Quote:
}

close $server;
-----

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 19 Oct 2002 03:00:00 GMT  
 Need help with Client/Server script using IO::Socket & File::Tail
Quote:

>I just need help getting the ability to start|stop the tail'ing while
>keeping the connection.

I don't see what the difficulty is (maybe that's because I'm the author of
File::Tail).

If you just want to stop reading temporarily, don't call any of File::Tail's
methods, and there won't be any run-time overhead.
If you want to stop reading, then restart later without seeing what went on
in the meantime, just open a new Tail object - the old one will be GCed, and
the new one will continue reading from the present.

If your problem is how to wait for command from the other end _while_ sending
new data from the Tail through the connection, you need to use select on the
socket from the connection.

While the tail is operational, you should use File::Tail's select, which
knows how to wait on a combination of Tail and normal filehandles.
(See perldoc File::Tail).

When the tail is NOT operational, you use the normal select, although I think
File::Tail's select would work there just as well - it reverts to the
system's select to wait for normal filehandles.

Best regards,
        Matija

--
"My name is Not Important. Not to friends.
    But you can call me mr. Important"  - Not J. Important



Mon, 21 Oct 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Lib error PLEASE HELP

2. I need sample client/server program using Socket.pm

3. IO::Socket::INET server/client

4. IO::Socket - The server will not reply back to the client

5. Help with puzzling DB problem

6. Is DBRadioGroup buggy?

7. IO::Socket && IO::Select Problem

8. Simple TCP client using io::socket::inet not so simple

9. Getting a clients ip address using IO::Socket

10. Questions: CRT of Turbo Pascal for Windows 1.5

11. Stopping Paradox Table from posting

12. Need help with server / client perl scripts

 

 
Powered by phpBB® Forum Software