the reason for having threads is simple : one thread has to wait on a line arriving from the user (client), respond to it, and repeat for ever. The other has to just report back autonomously every second. The responses seen at the client should look like this:

OK OK ? report: 27 OK ? report: 36 OK

With OK and ? being the responses to client commands. As you say, they are received by the same piece of code which parses them and acts appropriately. That's fine, and nothing to do with needing threads, which is a result of needing to both wait for user input AND act autonomously.

The simple solution, which I'll likely take, is juts to poll periodically from the client. I just liked the idea of being able to say "start reporting" ... "stop reporting" instead of that.


In reply to Re^2: sharing a socket between two threads (win32) by danmcb
in thread sharing a socket between two threads (win32) by danmcb

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.