yoop has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w -T package MyPackage; use strict; use base qw(Net::Server::PreFork); MyPackage->run({port => 20205, no_client_stdout => 1}); sub process_request { my $self = shift; eval { local $SIG{'ALRM'} = sub { die "Timed Out!\n" }; my $timeout = 5; my $sock = $self->{server}->{client}; $sock->autoflush(1); $|=1; while (defined (my $buf = <$sock>)) { $buf =~ s/\r?\n$//; #sleep(5); print $sock "client said '$buf'\r\n"; alarm($timeout); $sock->close(); } alarm(0); }; if ($@ =~ /timed out/i) { print STDOUT "Timed Out.\r\n"; return; } } 1;
#!/usr/bin/perl -w use IO::Socket::INET; my $sock = new IO::Socket::INET (Blocking => 1, PeerAddr => 'localhost +', PeerPort => '20205', Proto => 'tcp'); my $clean_content = ""; die "Could not create socket: $!\n" unless $sock; $sock->autoflush(1); $|=1; $sock->send("message to server\r\n"); while (<$sock>) { print $_; } close $sock;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Server::PreFork requires new line to end input
by betterworld (Curate) on Aug 31, 2008 at 23:15 UTC | |
|
Re: Net::Server::PreFork requires new line to end input
by karavelov (Monk) on Aug 31, 2008 at 22:51 UTC | |
|
Re: Net::Server::PreFork requires new line to end input
by yoop (Initiate) on Sep 01, 2008 at 20:41 UTC |