Something like this? Only handles a single request at a time, though.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11134663 use warnings; use IO::Socket; use IO::Select; my $listen = IO::Socket::INET->new( LocalPort => 8080, # setup Listen => 256, Reuse => 1) or die $@; my $sel = IO::Select->new($listen); sub checkforrequests { for my $fh ( $sel->can_read(0) ) # 0 for poll { my $socket = $fh->accept; my $request = ''; 1 while sysread $socket, $request, 4096, length $request and not $request =~ /\n\r?\n/; # empty line test print $request =~ s/^/got HTTP packet: /gmr; # FIXME for testing # FIXME process request here print $socket "OK\n"; # FIXME sample response $request =~ /quit/ and die "exiting on 'quit'\n"; # FIXME for test +ing } } while( 1 ) # your loop as I understand it { select undef, undef, undef, 0.2; # FIXME your non-network stuff checkforrequests(); # this is added to your loop }

I used wget to talk to it, like this

wget -q -O - http://localhost:8080/CMD=changeplaylist

and I get an output of

got HTTP packet: GET /CMD=changeplaylist HTTP/1.1 got HTTP packet: User-Agent: Wget/1.21.1 got HTTP packet: Accept: */* got HTTP packet: Accept-Encoding: identity got HTTP packet: Host: localhost:8080 got HTTP packet: Connection: Keep-Alive got HTTP packet:

A clever client could hang it if it tried. Should probably be done with a more extensive multi-connection handler, but they get bigger :)
( Which is why monks, including me, will suggest using an async package.)


In reply to Re^5: Adding simple HTTP controls to existing code by tybalt89
in thread Adding simple HTTP controls to existing code by brachism

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.