Debugging the client- server program
- From: "mina" <janicehwang1325@xxxxxxxxx>
- Date: 28 Apr 2006 01:01:56 -0700
hi all.. below is my program for simple SSL client-server program. It
runs well, however, whenever i press CTL+C on either end. The following
error pop up:
"SSL read errorerror:00000000:lib(0):func(0):reason(0)
at /usr/local/lib/perl5/site_perl/5.8.6/IO/Socket/SSL.pm line 543"
I dun really understand wat happen... is it because of my "force"
exiting the program? is there any way to improve it?
SSL_server.pl:
===========
#!/usr/bin/perl
use IO::Socket::SSL qw(debug2);
my ($sock, $s, $v_mode);
if($ARGV[0] eq "DEBUG") { $IO::Socket::SSL::DEBUG = 1; }
# Check to make sure that we were not accidentally run in the wrong
# directory:
unless (-d "certs") {
if (-d "../certs") {
chdir "..";
} else {
die "No CA Certs\n";
}
}
if(!($sock = IO::Socket::SSL->new( Listen => 5,
LocalAddr => 'localhost',
LocalPort => 1234,
Proto => 'tcp',
Reuse => 1,
SSL_verify_mode => 0x01,
SSL_use_cert => 1,
SSL_passwd_cb => sub {return "haha"},
SSL_key_file => 'certs/server_key.pem',
SSL_cert_file => 'certs/server_certs.pem',
)) ) {
warn "unable to create socket: ", &IO::Socket::SSL::errstr, "\n";
exit(0);
}
warn "SSL socket created: $sock.\n";
while (1) {
warn "waiting for next connection......\n";
while(($s = $sock->accept())) {
print $s "Welcome to $0; alern me where there is new
file.....\n";
my ($peer_cert, $subject_name, $issuer_name, $date, $str);
if( ! $s ) {
warn "error: ", $sock->errstr, "\n";
next;
}
warn "connection opened ($s).\n";
if( ref($sock) eq "IO::Socket::SSL") {
$subject_name = $s->peer_certificate("subject");
$issuer_name = $s->peer_certificate("issuer");
warn "\t subject: '$subject_name'.\n";
warn "\t issuer: '$issuer_name'.\n";
while ( <$s>) {
print "from client > $_";
next unless /\S/; # blank line
if (/quit|exit/i) { last;
}
elsif (/unequal/i) { printf $s "the file is
unequal\n"; }
elsif (/equal/i ) { printf $s "the file is
equal\n"; }
#this is when the user type help
else {
print $s "Encrypted Text\n";
}
}
}
#warn "\t subject: '$subject_name'.\n";
#warn "\t issuer: '$issuer_name'.\n";
# my $date = localtime();
# print $s "my date command says it's: '$date'";
# close($s);
# warn "\t connection closed.\n";
}
}
#$sock->close();
#warn "loop exited.\n";
SSL_client.pl:
==========
#!/usr/bin/perl
use IO::Socket::SSL qw(debug2);
use Tie::File;
use File::Compare;
$path = "/usr/home/extol/testing/SocketProgramming/sampleStorage/";
$filename = "filename.log";
$outfile = "outfile.log";
$naptime = 1;
my ($v_mode, $sock, $buf);
if($ARGV[0] eq "DEBUG") { $IO::Socket::SSL::DEBUG = 1; }
# Check to make sure that we were not accidentally run in the wrong
# directory:
unless (-d "certs") {
if (-d "../certs") {
chdir "..";
} else {
die "Cannot find the directory /certs\n";
}
}
if(!($sock = IO::Socket::SSL->new( PeerAddr => 'localhost',
PeerPort => '1234',
Proto => 'tcp',
SSL_use_cert => 1,
SSL_key_file => 'certs/client_key.pem',
SSL_cert_file => 'certs/client_certs.pem',
SSL_verify_mode => 0x01,
SSL_passwd_cb => sub { return "opossum" },
))) {
warn "unable to create socket: ", &IO::Socket::SSL::errstr, "\n";
exit(0);
} else {
warn "connect ($sock).\n" if ($IO::Socket::SSL::DEBUG);
}
# check server cert.
my ($subject_name, $issuer_name, $cipher);
if( ref($sock) eq "IO::Socket::SSL") {
$subject_name = $sock->peer_certificate("subject");
$issuer_name = $sock->peer_certificate("issuer");
$cipher = $sock->get_cipher();
}
warn "cipher: $cipher.\n", "server cert:\n",
"\t '$subject_name' \n\t '$issuer_name'.\n\n";
die "cant fork: $!" unless defined($kidpid = fork());
if ($kidpid) {
# copy the socket to standard output
while (defined($line = <$sock>)) {
print STDOUT "from server > $line\n";
}
kill("TERM", $kidpid); # send SIGTERM to child
}
else {
# check if the file is ready in the folder
for(;;){
#list all the filename in the sampleStorage into filename.log
`ls $path > filename.log`;
# Get the filename to be only argument to be concern
open (IN, $filename) || die "Could not open $filename: $!";
while (<IN>) {
#comparing two files
if(compare($filename,$outfile) == 0){
$line = "equal\n";
print $sock $line;
}
else{
my $line = "unequal\n";
print $sock $line;
#check the differ point
$countIn = `wc -l < $filename`;
$countOut = `wc -l < $outfile`;
$diff = $countIn - $countOut;
while($diff > 0 && $countOut < $countIn){
tie @inline, Tie::File,$filename or die
"can't update $filename:$!";
chomp($inline[$countOut]);
print "sending......\n";
`echo "$inline[$countOut]" >>
$outfile`;
$diff--;
$countOut++;
}
}
}
sleep $naptime;
IN->clearerr();
}
}
#close (IN);
#my ($buf) = $sock->getlines;
#$sock->close();
#print "read: '$buf'.\n";
.
- Follow-Ups:
- Re: Debugging the client- server program
- From: usenet
- Re: Debugging the client- server program
- Prev by Date: Re: How to test result of an extraction?
- Next by Date: Re: SSL
- Previous by thread: simple wildcard regex problem.
- Next by thread: Re: Debugging the client- server program
- Index(es):
Relevant Pages
|