1

I'm new to IPC using pipes and I'm not familiar with the usual patterns. Here is the setup I have to deal with: There is a client process that distributes work to n server processes. After finishing, the servers have to send their results back to the server. The amount of work that has to be distributed is known from the beginning.

Client
  |__Pipe 1_____ Server 1
  |
  |__Pipe 2_____ Server 2
  |
  |__ ...

Here my idea, how to deal with this: The servers are started with a command line argument determining the name of the pipe they shall create when starting up. The client then writes to those pipes to distribute work. When the servers finish their job, they write their results to the pipe they received the job from. The client waits with n threads for the results from the servers. When all results arrived, the partial results are assembled.

Do you think this makes sense? Would you see advantages in using a single pipe in one of the directions? How would you synchronize access? Do you have reading tips on the topic?

h0b0
  • 1,802
  • 1
  • 25
  • 44

1 Answers1

1

I'm by no means an expert in named pipes, but from the little work I with them, you can have multiple servers running on the same named pipe. When a client attempts to connect, the first available server is matched with the client.

So you can have a single named pipe that has say ten servers listening to it, and when clients request a connection they will be assigned an available server, thereby providing some sort of basic load-balancing mechanism. You can also have a single client open multiple connections to the same named pipe, and so each connection will be connected to a different server instance.

That way answers will be provided on the established connection, but you won't have to manage and coordinate pipe names between the servers and the client.

Allon Guralnek
  • 15,813
  • 6
  • 60
  • 93
  • It turned out to be THAT easy. A client simply connects to the next free server and opens an own pipe instance. So using a single pipe is really enough. See also http://stackoverflow.com/questions/4570653/multithreaded-namepipeserver-in-c-sharp. – h0b0 Dec 21 '11 at 11:00