A little bit of background first: I'm thinking of writing a MUD server (well, it's more like an extensible MUD engine, such as the Gecko engine is to web browsers). I'm thinking of writing it in Perl for a variety of reasons, then backporting parts of it to C if speed becomes an issue. Unfortunatly, right now I'm stuck at the very beginning.

I've looked over examples of sockets code, I read the IPC chapter in the Camel, looked at a few C primers on networking and sockets and did my research. As far as I can tell there are three main ways to deal with multiple concurrent connections and I don't know which one would be best for the job I'm trying to do.

From what I've seen, you can use fork() to split off a child for each open connection, use select() to switch between sockets, or use a threaded model.

Can anyone tell me what the advantages and disadvantages to each of these models would be, aside from the obvious (threads require threadsafe modules and so forth)? Why should I choose one model over another? What are the limitations of each model? What are the benefits? What are the common gotchas and pitfalls for implementing each of the models? Am I going to run into portability problems trying to move between Win32/Cygwin and Unix?

To sum up my problem, There's More Than One Way To Do It But Which Way Is Best?

Much obliged.


In reply to Sockets: TMTOWTDI (BWWIB)? by Ionizor

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.