Using named pipes in applications

Using named pipes in applications




How can I implement two way communication between one server and several
clients?




It is possible that more than one client is communicating with your
server at once. As long as each command they send to the server is
smaller than PIPE_BUF (see above), they can all use the same
named pipe to send data to the server. All clients can easily know the
name of the server's incoming fifo.



However, the server can not use a single pipe to communicate with the
clients. If more than one client is reading the same pipe, there is no
way to ensure that the appropriate client receives a given response.



A solution is to have the client create its own incoming pipe before
sending data to the server, or to have the server create its outgoing
pipes after receiving data from the client.



Using the client's process ID in the pipe's name is a common way to
identify them. Using fifos named in this manner, each time the client
sends a command to the server, it can include its PID as part of the
command. Any returned data can be sent through the appropriately named
pipe.






Home FAQ