in reply to Socket buffer errors

haukex / kcott - Thanks for the suggestions. As additional explanation, this routine only needs to accept and process input. No response is sent back to the sensor and only one sensor provides input. So the simplest routine possibly is preferred.
kcott - Each message received consists of 5 lines. All messages are identical except for the sensor data in the request line.
   A request line.
   Three header lines (host, connection, user-agent).
   A blank line.
The request line format is:
GET /DATA_String/{300 continuous characters of sensor data}HTTP/1.1
A message is received approximately every minute. Processing by the called routine requires approximately 22-24 msec. Everything seems to work except the listen queue doesn’t seem to clear after the input is read to the buffer resulting in the listen queue overflow.

Replies are listed 'Best First'.
Re^2: Socket buffer errors
by kcott (Archbishop) on Apr 15, 2023 at 04:45 UTC

    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