Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Socket buffer errors

by Marshall (Canon)
on Apr 15, 2023 at 16:39 UTC ( [id://11151686]=note: print w/replies, xml ) Need Help??


in reply to Socket buffer errors

Evidently the sender makes a TCP connection, sends some data, and then terminates the socket. You should terminate at your end and wait for a new request. Move the close socket statement up into the loop and of course, it should be on $new_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"); } } close ($new_sock); ########################### }
There are some low-probability failure modes with the above code. There are some things beyond your control that could cause the accept() to fail, so normally the loop condition would be:
while (1) { $new_sock = $sock->accept() || next; ....
There can be some issues with the way that you are reading the socket depending on what the sender is actually doing. You will be ok as long as the entire record is contained in a single MTU (transmission unit).

Update: If requests are piling up because you cannot process them in actual receive time, then I would just append the data line to a file instead of trying to process it before the next request comes. Have a separate program reading that file and processing line by line. Of course, that file will grow since more is coming in than is being processed. Or do some way of processing these data lines en masse - launching a process per line is "expensive".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11151686]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found