Troubleshooting the client program
- From: "mina" <janicehwang1325@xxxxxxxxx>
- Date: 25 Apr 2006 00:37:21 -0700
Below is my client program...I put all the filenames in a directory
into a file named fileaname.log and the program will check if the
oufile.log has the same content. If it is not the same, it will compute
the difference between 2 files by counting line and insert differ lines
into the output file.. However, i would like to run this program as
real time.. but, it seems like not. whenever changes i made to the
filename.log would not reflect in the running client program. How to
achieve this?? i try to run the client program, putting new line into
filename.log, it does not reflect the changes. Instead, the new line
disappear as well...
another problem is i would like to run this program continuosly like
the server. How would i achieve that? is it just dun close the
connection in the server side will do?
#!/usr/bin/perl -w
#use strict;
use IO::Socket;
use IO::Handle;
use Tie::File;
use File::Compare;
use Fcntl;
my ($host, $port, $kidpid, $handle, $line, $path, $filename,$outfile,
$naptime);
my ($countIn, $countOut, $diff);
$path = "/usr/home/extol/testing/SocketProgramming/sampleStorage/";
$filename = "filename.log";
$outfile = "outfile.log";
$naptime = 1;
#list all the filename in the sampleStorage into filename.log
`ls $path > filename.log`;
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) = @ARGV;
# create a tcp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to port $port on $host: $!";
#the autoflush method is used on the socket because otherwise the
system
#would buffer up the output that we sent
$handle->autoflush(1); # so output gets there right away
print STDERR "[Connected to $host:$port]\n";
# split the program into two processes, identical twins
die "can't fork: $!" unless defined($kidpid = fork());
# the if{} block runs only in the parent process
if ($kidpid) {
# copy the socket to standard output
while (defined ($line = <$handle>)) {
print STDOUT "from server > $line\n";
}
kill("TERM", $kidpid); # send SIGTERM to child
}
# the else{} block runs only in the child process
else {
# Get the filename to be only argument to be concern
open (IN, $filename) || die "Could not open $filename: $!";
# check if the file is ready in the folder
while (<IN>) {
#comparing two files
if(compare($filename,$outfile) == 0){
print "the file is equal\n";
}
else{
print "the file is unequal\n";
#check the differ point
$countIn = `wc -l < $filename`;
$countOut = `wc -l < $outfile`;
$diff = $countIn - $countOut;
print "diff is $diff\tin is $countIn\tout is $countOut\n";
while($diff > 0 && $countOut < $countIn){
tie @inline, Tie::File,$filename or die "can't update
$filename:$!";
chomp($inline[$countOut]);
print "count $diff:$inline[$countOut]\n";
`echo "$inline[$countOut]" >> $outfile`;
print "the infile log[$countOut] is:$inline[$countOut]\n";
$diff--;
$countOut++;
}
}
}
close (IN);
}
.
- Follow-Ups:
- Re: Troubleshooting the client program
- From: mina
- Re: Troubleshooting the client program
- Prev by Date: Re: Running Perl Code in Windows
- Next by Date: Problem while using Lingua::Wordnet...
- Previous by thread: Cookies
- Next by thread: Re: Troubleshooting the client program
- Index(es):
Relevant Pages
|