Tech Support > Computers & Technology > Programming > How to use named pipes?
How to use named pipes?
Posted by Ramon F Herrera on January 25th, 2005


This is my first attempt to write a server, so I'd
appreciate some guidance from you folks out there.

My application has to generate a big hash and then
perform searches on that structure every once in a
while. The hash contents (it is a K-D tree) are
constant and every minute or so there is a query
of the nearest neighbor in the tree. I simply hate
having to reconstruct the fixed tree every time the
program starts. So I figure I need a client-server
architecture. The server assembles the big tree and
just waits for queries. I suspect that something called
a "named pipe" would be appropriate here but I need help
with the implementation details (or perhaps there is
a suggestion for a better solution?).

The client program has to place a point (two integer
numbers) in the pipe and somehow expect the results
(a set of a few points) to be produced by the server.

A named pipe can be seen in the filesystem, right?

I don't have my Unix books handy. Is there any sample
code, or tutorial around?

TIA,

-Ramon F Herrera

Posted by Ramon F Herrera on January 25th, 2005


I am going to be more specific in my posting.

My server will spend most of its time doing nothing, and
I am trying to decide how to wait in an efficient manner.

Should the server simply open the named pipe for reading
and then the process will just block for a long time until
finally there is something to be read form the pipe?

It this a efficient implementation? Or perhaps the server
should do some sleep() and check the status of the
pipe (how?) periodically before attempting to read it??

-Ramon

Posted by moi on January 25th, 2005


Ramon F Herrera wrote:
If your server spends most of it's time doing nothing, there will be no
need for doing that efficiently, IMO.

There is no difference between being blocked in a read() or in a
select() or poll(). You could even block on a sleep or wait: won't cost
you nothing, except for the block.
Instead of a pipe you could use a socket connection. No difference for
your program, basically. A bit more difficult setting up, but a few
advantages.

HTH,
AvK

Posted by Petr Lorenz on January 25th, 2005


As far as pipes are concerned, I think I saw something like blocking and
non-blocking pipes. The blocking pipes should sleep automatically until
a message arrives.

Other possibility for writing a server is to use sockets. Try to look at:
http://www.amk.ca/python/howto/sockets/
It is a small howto for sockets in Python. You can make like that a very
small (in code length) and you do it very fast (in time spent) server
client application.

Petr.

Ramon F Herrera wrote:


Similar Posts