2

I have N worker processes and a server process that started those workers. Now I want my workers to communicate to the server in two ways (WorkerK --> Server and Server --> WorkerK).

What is the best way to do this?

I read about MemoryMappedFiles, NamedPipes and some others. Which one should I choose and why?

My project is Windows Forms Application.

Nickon
  • 9,652
  • 12
  • 64
  • 119

1 Answers1

1

If you don't know anything about communication, pick an off the shelf solution. A Bidirectional WCF channel is a good example. See What You Need To Know About One-Way Calls, Callbacks, And Events for a primer. Read WCF Overview (including all the links!) for an introduction into WCF.

If you are more versed into communications then you should had defined the problem more clearly:

  • what authentication model is used? Kerberos, certificates, password, none?
  • intranet or internet?
  • who's doing the listenning? your own service, http.sys, WCF activation?
  • and the most fundamental question: syncronous or asynchronous? And I do not mean asyn as an async API, but async as in queued message oriented protocol.
Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
  • No authentication. There are only simple worker processes, all of them on the local machine, so intranet. But all the apps are Windows Forms Applications. It's a program that does some CPU consuming calculations, so there are some different processes run in the same time that are being coordinated by a main process. So they work async, but I would like to make some communication between them to share some data. – Nickon Aug 29 '13 at 13:04
  • Why do you need separate processes? Why cannot these be threads inside same process? – Remus Rusanu Aug 29 '13 at 13:11
  • Because you can set a processor affinity for each one as they are processes – Nickon Aug 29 '13 at 13:13
  • 1
    You're paying a huge, huge price for that small benefit. And what's wrong with [`SetThreadAffinityMask`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms686247(v=vs.85).aspx) – Remus Rusanu Aug 29 '13 at 13:15
  • When I wanted to raise threads priority to give them whole CPU time (as much as possible), then it didn't work even when I tried to set current process priority to realtime. When I did them as a separate processes, the PC started freezing (100% CPU usage). So the change is caused by low threads' priority:/ – Nickon Aug 29 '13 at 13:19
  • And in the future more experienced users will be able to execute the program from a command line to use more advanced functions. – Nickon Aug 29 '13 at 13:24
  • IMHO the best IPC locally is shared memory, but there is no programming API around it, you need to program yourself everything. The big advantage is that there is 0 copy, the two processes real read and write into the same physical location. – Remus Rusanu Aug 29 '13 at 13:25
  • 1
    If you're not into writing your own wire protocol, I strongly suggest using WCF. You can use it with a fast transport (pipes or socket) w/o resorting to HTTP overhead. – Remus Rusanu Aug 29 '13 at 13:27
  • 1
    A solution arhcitected on a queueing backbone (0mq, activemq, msmq) for sure will be more elegant and will be able to scale out easier in the future (possibly). But is probably overkill right now, at the least because of deployment/administration requirements (install, configure). – Remus Rusanu Aug 29 '13 at 13:29
  • I'm just looking at MSMQ solution from here: http://stackoverflow.com/a/11077167/1252575 – Nickon Aug 29 '13 at 13:31