I have a (small?) proof-of-concept-demo server I did, that was nonblocking, but this is a HTTP server (it also has push HTTP, I was thinking of using it as a shared database for volatile data like internet connection status and other status information of the network.

The server assumes that it can always gobble in a complete client request/client line at one time, I was too lazy to also implement blocking for reading and not only for writing... You will have to add a buffer there as well ... Or maybe I've added that too - I don't remember, as this code is about 1 year old ;)

The commands it has are "GET", "SET" and "UNSET" and some more, it has (if I remember right) even the possibility to access it with a "normal" http-browser, but it prefers clients that keep the connection open.

The code should work as-is on any OS, but if you are setting it up for public use, you will surely add use warnings; (which I do via the command line) and use strict; (which I didn't use back then).

Update : I added some documentation in the code, mainly around the select() statements (which aren't even select() but IO::Select statements ...).

Update : Thanks to mdillon for suggesting I put the /o modifier on the constant REs. Also, by looking again over the code, this code readily will execute arbitrary Perl code with the SOURCE command. While this allowed me to create cool commands/keys like WHO in cgi-bin fashion, this will be a major security issue for you (or maybe not, as you will have 10 clients on your server that could be well-behaved ...)

Update: I've moved the code into the Code Catacombs, it is now available (together with the ad-hoc documentation) at Push HTTP Server.

Update: Currently the link is broken because the code node has vanished. We are doing the necessary rituals for revivification of the node. Please stand by.


In reply to Re: Socket.pm nonblocking by Corion
in thread Socket.pm nonblocking by Phil

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.