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).

— Ken


In reply to Re^2: Socket buffer errors by kcott
in thread Socket buffer errors by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.