Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

TCP Client and Server Inter process communication

by askii (Novice)
on Jun 11, 2010 at 13:21 UTC ( [id://844236]=perlquestion: print w/replies, xml ) Need Help??

askii has asked for the wisdom of the Perl Monks concerning the following question:

I am well versed in perl and have built many TCP clients and servers separately which have worked very well. I am now in a position, after much reading needing someone much wiser than I to put the two together.

My problem is as follows

TCP Client -> Connects to a remote end and maintains the connection. It talks a protocol and has keep alives within it. This works well and is based on IO::Socket and IO::Select modules of which there are many examples.

TCP Server -> Recieves TCP connections and handles data correctly. Again simple enough and I have a forking model so multiple connections can be handled as needed.

Now the problem I face is that the TCP Server needs to send data to the TCP Client in a non blocking manner, such that the TCP Client connection to a remote server must be maintained but it must recieved data from the TCP Server, when available.

So little ASCII art to help

TCP Client -> Connection to a remote end
^
|
TCP Server <- Receives TCP connections and handles data and should send the data to the TCP Client, while the TCP Client maintains the connection to the remote end.

My current code tried to combine the two, uses pipe for reading writing, however I am stuck as how to manage the select between the TCP Client to the remote server and the incoming data from the TCP Server, so they do not block each other.

It is also requirement for the TCP Server to handle multiple requests, so forking not a problem, but how those processes talk to the TCP Client, without blocking etc.

I am sure this is a fairly simple implementation however IPC is something I have not done in anger before and pointers welcome/required.

I have not posted code directly but can provide if needed.

A

Replies are listed 'Best First'.
Re: TCP Client and Server Inter process communication
by dk (Chaplain) on Jun 11, 2010 at 13:45 UTC
    I have built many TCP clients and servers

    I assume that you have built many blocking servers, but you have trouble with non-blocking architecture, am I right? If that's so I'd recommend to try one of CPAN's async I/O toolkits - POE, IO::Lambda, AnyEvent, EV . Sure you can do the same without a toolkit, it just gets messy; begin with perldoc -f select if you need to build it from the ground up.

Re: TCP Client and Server Inter process communication
by kirillm (Friar) on Jun 11, 2010 at 21:05 UTC

    If you're familiar with creating non-blocking network servers and clients, maybe you could make TCP Client (with capital "C") act as a TCP server (with small "s") for connections from the TCP Server (with capital "s") rather than using pipes? TCP Server would simply connect to the TCP Client and send some data.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://844236]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-29 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found