I have a sensor that sends data using an HTTP write that I want to log. I am new to socket programming but found an example in O’Reilly’s “Advanced Perl Programming”. After adjusting the code for my network, I get the input properly from the sensor and am able to process it without problems.
The code is:
#!/usr/local/bin/perl
#
# usage:
#
use warnings;
use strict;
use IO::Socket;
open PIDfile, '>', '/var/run/aws.rcvr.pid';
print PIDfile "$$\n";
close PIDfile;
my ($sock, $new_sock, $buf );
$sock = new IO::Socket::INET (LocalHost => '192.168.100.7',
LocalPort => 8081,
Proto => 'tcp',
Listen => 1,
Reuse => 1
);
die "Socket could not be created. Reason: $!" unless $sock;
while ($new_sock = $sock->accept()) {
while (defined ($buf = <$new_sock>)) {
if (index($buf, "/DATA_String/") > 0) {
system("sh", "/home/app_scripts/process.input", "$buf");
# } else {
}
}
}
close ($sock);
I run the code on a FreeBSD 13.0 system in background. However I am doing something wrong (or have missed something) because I get the error:
+sonewconn: pcb 0xfffff8003e9f4d90 (192.168.100.7:8081 (proto 6)): Listen queue overflow: 2 already in queue awaiting acceptance (6 occurrences)repeatedly in the system logs. I tried increasing the buffers but that just increased the number in the queue. Can someone explain what is wrong or point me to a more appropriate example?
TIA - JJ
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.