Drip-feeding us bits of information isn't really appreciated.
Please read "How do I post a question effectively?" and "Short, Self-Contained, Correct Example".
As it stands, we don't know anything about the client side beyond "sends data using an HTTP write";
we don't know what "/home/app_scripts/process.input" does;
and "PIDfile" is a complete mystery (you open, write, close, and never use again).
Here's a scenario that works.
It does the sort of things that you say you want to achieve.
It doesn't generate any error or warning messages.
Adapt to your needs.
ken@titan ~/tmp/pm_11151665_io_socket
$ ls -l
total 4
-rwxr-xr-x 1 ken None 387 Apr 15 13:51 client.pl
-rwxr-xr-x 1 ken None 50 Apr 15 11:57 process.sh
-rwxr-xr-x 1 ken None 464 Apr 15 13:58 server.pl
-rw-r--r-- 1 ken None 200 Apr 15 14:01 test.log
client.pl:
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Socket;
my $client = IO::Socket::INET::->new(
Proto => 'tcp',
PeerAddr => 'localhost',
PeerPort => 55555,
) || die "Can't open client socket: $IO::Socket::errstr";
for my $send_num (1 .. 5) {
$client->print(<<"EOT");
GET /DATA_String/{send_num = $send_num}HTTP/1.1
host
connection
user-agent
EOT
sleep 5;
}
server.pl:
#!/usr/bin/env perl
use strict;
use warnings;
use IO::Socket;
my $server = IO::Socket::INET::->new(
Proto => 'tcp',
LocalPort => 55555,
Listen => SOMAXCONN,
ReuseAddr => 1,
) || die "Can't open server socket: $IO::Socket::errstr";
my $client = $server->accept();
$client->autoflush;
while (defined(my $read = <$client>)) {
chomp $read;
if (index($read, 'GET /DATA_String/') == 0) {
system('sh', 'process.sh', $read);
}
}
process.sh:
#!/usr/bin/env sh
echo -e "$*" >> test.log 2>&1
Start server.pl then start client.pl.
These will finish after ~25secs.
Now check the log.
$ cat test.log
GET /DATA_String/{send_num = 1}HTTP/1.1
GET /DATA_String/{send_num = 2}HTTP/1.1
GET /DATA_String/{send_num = 3}HTTP/1.1
GET /DATA_String/{send_num = 4}HTTP/1.1
GET /DATA_String/{send_num = 5}HTTP/1.1
See also:
IO::Socket;
IO::Socket::INET;
and, perlipc.
The perlipc page has a lot of content;
if you don't want to read it all, concentrate on
"TCP Clients with IO::Socket"
and "TCP Servers with IO::Socket"
(which should answer questions you might have about my code).
|