LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-04-2008, 01:47 PM   #1
alix123
Member
 
Registered: Nov 2004
Posts: 63

Rep: Reputation: 15
Red face 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???
 
Old 10-05-2008, 07:36 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994Reputation: 1994
Do you receive anything from client at the server end? Is it a firewall issue?
BTW, don't use &subname() in v5.x. That was a v4 thing. Now it basically means a ref to a sub, which is not what you want.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl socket stopping Fredde87 Programming 3 03-06-2008 04:05 AM
Perl socket daemon twantrd Programming 10 01-10-2008 04:04 AM
Raw socket with perl Whiteghost Linux - General 1 10-14-2005 10:29 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
use IO::Socket help (perl) vexer Programming 0 03-06-2003 08:47 PM


All times are GMT -5. The time now is 01:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration