In my experience, you need to open 2 sockets: one to to listen for and accept incoming connections, and the other to connect to the other server.

If I'm understanding your 2 posts correctly, I would imagine a processing flow like:

  1. Remote Server listens on a port for incoming connections.
  2. When an incoming connection is detected, delegate a worker process/thread.
  3. Worker accepts the connection while the Remote Server resumes waiting for incoming connections.
  4. Worker receives the message and validates it.
  5. If validation fails, worker sends a negative response, closes the connection then becomes idle (or terminates itself).
  6. Otherwise, worker sends a positive response, closes the connection then processes the message.
  7. If no results message needs to be sent, worker becomes idle (or terminates itself).
  8. Otherwise, worker opens a socket, connects to your Local Server and sends the results message.
  9. Worker waits for positive/negative response. Once received, closes the connection.
  10. Worker performs any needed follow up based on the positive/negative response.
  11. Worker becomes idle (or terminates itself).

In the case where the Remote Server is initiating the transaction, a worker would proceed as above as though it were sending a results message. Any results sent back from the Local Server would be handled be handled the same as accepting requests as above.

I am sure there are modules/frameworks in CPAN that can handle the network part, especially if the communication between the Remote and Local servers is HTTP based.


In reply to Re: Bidirectional Client/Server - to fork or not to fork? by RonW
in thread Bidirectional Client/Server - to fork or not to fork? by ljamison

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.