Sockets is somewhat vague, anyway all sockets methods I know of are bidirectional. So, first of all, no need to have a couple of them - they're not pipes or fifos! This should half the complexity :)
Second, you probably have to decide who's the server and who's the client. Even if it may seem strange, I'd put the man-in-the-middle as a client, simply because... I forecast it will be simpler to code. A matter of taste and of forecasting powers, anyway.
This issue, tough physically completely independent on the following algorithm, is logically connected. How would you implement it inside a single process, reading from three files? Here you have much the same scenario, only with a bit of control logic to avoid reading more than you need. Again, the man-in-the-middle process will be the master driver, while the other two will act as slaves (i.e. servers).
The first and third process (i.e. the "endpoints"):
The second follows the same logic as a "single-process" computation: each time the process wants to read from one of the "side" file, it sends a fake command (a simple newline will do) to the corresponding far process, then reads the answer as if it were reading from a file. The core algorithm does not need to be changed, as you can see.Open file Open socket in server mode Accept incoming request Loop: read a request from the socket if request is "stop" exit else read name from file and send back to the socket
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
In reply to Re: sockets and such in Perl
by polettix
in thread sockets and such in Perl
by scotchfx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |