http://qs1969.pair.com?node_id=11134663

brachism has asked for the wisdom of the Perl Monks concerning the following question:

Probably simple, but I have just started dabbling in Perl. Working on a personal project for the home, I am trying to find a simple, quick, and lightweight method of integrating HTTP input into one of my projects. Most of my similar efforts have utilized NodeMCU’s. Years of using these seem to be clouding my judgement for an effective solution in Perl, a language I am learning.

My existing host’s core code is essentially an endless loop managing a series of host events. The client should be able to send occasional requests to either ‘set something’ or ‘inquire about something.’ The host responses in simple text, either 'ERR', 'OK' or with a short string. The reply to the client will be almost immediate, as the requests just set or return variables. Growing up with dial-up modems, my commands are AT-styled.

For example, to start execution, the follow client request results in $runflag=1
http://host:8080/CMD=ATES

I’ve looked at a few packages, such as HTTP::Server::Simple::CGI. While trying to incorporate the associated examples into my code, all block my main program while waiting for a client. The solution I need, is one where I can frequently poll for a client request. My main loop fire about 5 times a second.

Other notes:
- Single client, via HTTP (no SSL), on local network, no authentication
- Client send a command and wait for a response. E.g. http://ava/cmd=ATEP# (0=pause,1=un-pause)
- Host returns a simple text reply “OK”, “ERR”, or a short line of text
- Once reply sent, communication is done; until if/when client send another request
- Response timing is not critical (as in seconds, not milliseconds)

# DEVICE (HOST) – PSEUDO-CODE httpd_init(8081); while (1) { # Manage a request if ($client.request) { # Parse and validate, if invalid client.send('ERR'); # If 'set something': set variables; client.send('OK'); # Elsif a ‘request something': return client(short_string); # clear/cleanup//connection done } # Main program – do things … # Be nice my_sleep(250); }
Any suggestions? Thanks in advance.