tags:

views:

187

answers:

2

Hi,

I want to create one server and one client(two separate programs) where in server creates two named pipes(i guess thats the minimum required for bidirectional flow of traffic) and then the client is started,and Client and server should be able to send and recieve data both ways all the time(full duplex types).I think that would require me to have non-blocking named pipes.Would like some help as i have been able to create half duplex type of communication but struggling to make a contineous seamless transfer of data between client and server happen.

Thanks

+5  A: 

Possible options:

  1. Local domain sockets: AF_LOCAL family with SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET type. The socket can be "in-memory", meaning you connect to it using a unique string, or it can be a socket file in the filesystem. It works just like any network socket, full-duplex.

  2. Two pipes: one for reading, one for writing (vice versa for the other process). Might be a bit more complicated keeping track of two pipes, as opposed to the local domain socket.

Helpful link Check out the part on Pipes and the one on Unix Sockets.

Ioan
Agreed - `AF_UNIX` / `AF_LOCAL` sockets are really what you want here.
caf
Hi,I know i should use sockets for such purposes but the requirement is of pipes.I have written code using two named pipes(one for reading and one for writing), and have been able to achieve bidirectional data flow.Logic is something like this,i open a named pipe for reading with O_NONBLOCK flag,start an infinite loop try to read the contents,if it returns more than 0 bytes,i open another pipe for writing(with flag O_NONBLOCk) and write the contents recieved to that pipe and close it.This is the server code i am explaining.It works,but when it is started it takes almost all of my cpu.
kush87
How can i bring that cpu usage down. Please help.
kush87
Your CPU usage is from that infinite loop. Unless you have other work to do, just block when reading the pipe. You might want to consider an event loop that can manage an idle poll of the reading pipe and allow you to do other work in the meantime.
Ioan
A: 

have you considered using select() to handle the reading named pipe?

Ekhiotz