I'm afraid the only way is to make the accepting program act as a proxy between the other program and the remote machine.
So basically, it'd look like this:
- Program A: incoming connection
- Program A accepts and does whatever needs to be done
- Program A finds that it is now Program B's responsibilty. Either 1) using the existing TCP connection between A and B, or 2) by establishing a new connection, A informs B about this.
- Program A maintains the connection to the host but doesn't do anything except for bidirectionally relaying all data it receives from either party.
- When program B is done as well, it tells A about it, either by sending a specific code over the existing connection or simply closing the one created in step 3.2.
- Program A performs the goodbye rituals as per protocol (such as sending a 'everything succesful' sort of status message) and closes the connection to the remote as well.
I could be mistaken, of course, but to my knowledge this is the only way to fulfill your requirements. It'd be much simpler, of course, if Program A could simply say "Hey, listen, I can't do anything for you anymore, but here, have this state information (session ID or just the session data, something like that, so that Program B will know what it's working with) and contact my friend, program B. You can find him on this-and-that address."
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.