I'm not sure if you can make it more simple than the following:

package Foo; use base qw(Net::Server::Fork); my @ports = qw(20203 20204 20205); my @dbs = qw(tom jim jane); my %p_map; @p_map{@ports} = @dbs; Foo->run(port => \@ports); sub process_request { my $self = shift; my $port = $self->get_property('sockport'); my $db = $p_map{$port}; print "Welcome! You connected on port $port - your db is $db\n"; # run default echo server $self->SUPER::process_request(@_); }

If you are really opposed to Net::Server you could always read through its guts to see what it is doing and roll your own. Or keep your life simple. Enjoy!

Update: I guess really though this example is cheating - I haven't started three servers. I've only started one server that is listening on three ports. But I think it would be much much easier to maintain.

Update 2: Looking at your code you want a PreFork server. Well then you'd need to do the following:
use base qw(Net::Server::PreForkSimple); Foo->run( max_servers => 5, # from jwlewis sample code max_requests => 5, port => \@ports, );

my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Re: Opening multiple forking servers by Rhandom
in thread Opening multiple forking servers by jalewis2

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.