#!/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;