I need to write a simple proxy + loadbalancer (NOT an http proxy) that will accept a connection and the first line of protocol, pick an actual server based on info in that first line plus data I have on server loads, and fork off a child that then channels everything from the client through itself to the selected server/port (and vice versa).

(The routing depends on data in the first line of protocol received from the client, so I can't just use a generic load-balancer; a large part of the point is hiding the splitting up of some overloaded servers from the client software.)

It looks like I can do this fairly easily using IO::Connect (all the pieces, how to set the backlog queue size, how to do non-blocking IO all seem pretty obvious).

Liking, in principle, using higher-level tools, I started looking at Net::TCP and sub-classes including Server. While I can create a server, accept a connection, and interact with that connection, I can't actually find how to do all the little adjustments to params, or how to do simple stuff like determining the IP address of the client that connected to me.

So, my question is -- for a really simple proxy like this, is there actually an advantage to me in using Net::TCP::Server, or is going straight to IO::Connect the right choice? And if I *should* be using n::t::s, is there perhaps a tutorial or HOWTO somewhere that would get me started better than just reading the man pages has?


In reply to Simple proxy: Net::Tcp::Server vs. IO::Connect by dd-b

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.