Perl alarm not working when reading for a socket , perl seems to be buggy
I have a simple Socket Client which is waiting for a server reply if it does't received alarm should trigger and close the socket and exit. However alarm never triggers. here are my client and server.
########### My Client #######
use IO::Socket;
$socket = IO::Socket::INET->new
(
PeerAddr => 'localhost',
PeerPort => 1247,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create client.\n";
print $socket "STATUS\n";
&WaitForServer();
sub WaitForServer()
{
$timeout = 10;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
alarm 10;
$line=<$socket> ; #it just hangs here as sever never replies
alarm 0;
};
if ($@) {
die unless $@ eq "alarm\n"; # propagate unexpected errors
# timed out
}
else {
print " I GOT the line $line";
close $socket;
# didn't
}
}
##Here is MyServer.pl ###################33
$server = IO::Socket::INET->new
(
LocalPort => 1247,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 5
) or die "Could not create server.\n";
while ($client = $server->accept()) {
while ($line = <$client>) {
print "Read this from client: $line";
# print "sending back status to cient \n";
#print $client "Iam running\n";
}
}
############# Server Ends here###################
Any solution for the above will be really helpfull ?? I'am using perl 5.10
Perl in windows Really seems to be buggy earlier i was trying the same program with fork( (see my last post ) however program hungs when doing the fork. Now I'am trying to workout with alarm now alarm is also not working???
|