Ok, I have this server script that I am currently writing for use with a gui front end. I am trying to do some simple auth with a user id and password, and for the most part it works just fine. Though I have come across a strang thing when sending a response back to the client. I am calling a sub that checks the id and password and returns the userid on good and undef on bad. The problem is that when I try to set the return to something the response never gets sent to the client. If I just call the sub by it's self everything works great .... any ideas
Thanx
sub Sserv {
my ($sever, $log, $logfile) = @_;
$server = IO::Socket::INET->new(
LocalPort => 3300,
Type => SOCK_STREAM,
Listen => 0,
Reuse => 1,
) or die $!;
open($log, ">> $logfile");
select((select($log), $| = 1)[0]);
while (my $conn = $server->accept) {
my $t = threads->create("gClnt", $conn, $log, $server) or die
+$!;
$t->detach;
}
}
sub gClnt {
my ($conn, $log, $server) = @_;
my $user;
while (defined(my $ans = <$conn>)) {
if (my $mess = chkAns($ans)) {
if ($mess =~ /^LOGIN_REQ:.*/) {
if ($user = userLogin($mess)) {
print $conn "GOOD";
}
else {
print $conn "BAD";
}
}
if ($user) {
print "$user:$mess\n";
KILLER($conn, $log, $server) if $mess =~ /^END_PROC_RE
+Q:.*/;
last if $mess =~ /^LOGOUT_REQ:.*/;
}
else { last; }
}
}
}
sub userLogin {
my ($mess) = @_;
if ($mess =~ m/^LOGIN_REQ:([\d \w]+):([\d \w]+)/) {
tie(my %db, 'SDBM_File', $userDB, O_RDWR|O_CREAT, 0666) or die
+ "Problem accessing user DB\n";
if (my $pass = $db{$1}) {
my $pwd = PwdCrypt->new($2);
if ($pwd->check($pass)) {
return $1;
}
}
untie %db;
}
return undef;
}
oh ya the chkAns sub is just a check sum for the request....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.