The usual way to do this is to have a parent process that is essentially always blocked on accept, with child processes that do the actual work. Fitting this into your framework would be something like this:

while ($client = $server->accept()) { $pid = fork(); if ($pid == 0) { print $client "Welcome to $0"; # etc. # Probably a loop here reading from $client # ... Other stuff exit 0; # Remember to go away when done! } # parent process here close $client; } # and go back to accept.
One thing missing from here is a throttle. You want to keep a count of active child processes so you don't keep creating new ones without any limit. Incrementing the counter is easy; the trick is to decrement the counter properly when each child process exits. In unix-land you can trap SIGCHLD for that, I don't know the equivalent on Win32. Whichever method you use, be careful to single-thread access to the counter. In other words, make sure when two children exit "at the same time", the counter really is decremented twice.

I haven't looked at the modules for handling forks. They may well solve this problem for you.

HTH


In reply to Re: Creating a server that accepts more than one client. by VSarkiss
in thread Creating a server that accepts more than one client. by boo_radley

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.