First I would recommend having a look at some generic solutions on CPAN, so that you can prototype quickly different approaches: some good ones are Net::Server, IO::Multiplex, IO::SessionSet and IO::SessionData in the lib directory of the perl network programming site (for non-blocking sockets in case you cannot trust your clients which is almost always the case ;))

Secondly if you maintain lots of open connections a select loop might be the way to go. Multiplexing on a few "select-loop " servers could be used to make the approach more scalable ( a request is sent to one of the children in the pool, and that child does the accept and adds the descriptor to the "select" set).

Finally studying part of the code of aproxy (a small TCP port forwarder) could be useful too

btw which platform are you on?

update Humm then there is the question of your bidirectional protocol. It is easy to do that part wrongly. I would suggest a fork for "each request to a connected client" (you need the socket descriptor of that client) IOW a fork for each server write... with COW schemes this does not have to be so costly. You could even prototype with doing a fork-exec of scripts in a server-request/ directory. It all depends on the average time of the request/answer (and your protocol). You'll need also to monitor the number of processes.

cheers --stephan


In reply to Re: TCP Socket, Forking, Memory exhaustion by sgt
in thread TCP Socket, Forking, Memory exhaustion by asuter

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.