Search or construction of an interprocess broadcast communication channel

Thus, we have this unusual need for our product. We have numerous processes running on the local host, and we need to build means of communication between them. The difficulty is that ...

  • There is no "server" or master process.
  • Messages will be broadcast to all listening sites
  • Nodes are all Windows processes, but can be C ++ or C #
  • Nodes will run simultaneously in both 32-bit and 64-bit versions.
  • Any node can enter / exit a conversation at any time.
  • The abnormal termination process should not adversely affect other nodes.
  • A process responding slowly should also not adversely affect other nodes.
  • A node does not need to "listen" to broadcast a message

A few important details ...

The β€œmessages” we need to send are trivial in nature. A message type name and one string argument would suffice.

Communication is not necessarily secure and does not require any means of authentication or access control; however, we want to group messages into a Windows login session. Perhaps the interest here is that an unsupported process should be able to interact with an elevated process and vice versa.

My first question is: is there an existing open source library? or something that can be used to accomplish this without much effort. At the moment, I could not find anything :(

If there is no library for this, then ... What technologies would you use to solve this problem? Sockets, named pipes, memory mapped files, event handlers? It seems that connection-based transport (sockets / pipes) would be a bad idea in a fully connected graph, since n nodes require n (n-1) number of connections. Using event handlers and some forms of shared storage seems like the most plausible solution right now ...

Update

  • Do I need to be reliable and guaranteed? Yes, and no ... Say that if I listen, and I respond within a reasonable time, then I should always receive a message.

  • What are the typical message sizes? less than 100 bytes, including message identifier and argument (s). They are small.

  • What level of messages are we talking about? Low bandwidth is acceptable, 10 per second will be a lot, average usage will be around 1 per minute.

  • What is the number of processes? I would like it to process from 0 to 50, with an average value of 5 to 10.

+6
c ++ c # ipc broadcast
source share
4 answers

I don't know anything that already exists, but you should be able to create something using a combination:

  • Memory mapped files
  • Events
  • mutex
  • Semaphore

This can be constructed in such a way that no "master process" is required, since all of them can be created as named objects, which are then managed by the OS and are not destroyed until the last client uses them. The basic idea is that the first startup process creates the objects you need, and then all other processes connect to them. If the first process terminates, the objects remain as long as at least one other process supports a handle for them.

A memory mapping file is used to exchange memory between processes. Mutex provides synchronization to prevent concurrent updates. If you want to allow multiple readers or one writer, you can build something like a read / write lock using a couple of mutexes and a semaphore (see Is there a global read / write lock? ). And events are used to notify everyone when new posts are posted.

I waved some important technical details. For example, knowing when to reset the event is pretty tough. Instead, you can get a poll of each application for updates.

But switching to this route will provide a non-contact way of exchanging information. This does not require the server-side process to always work.

For implementation, I would suggest implementing it in C ++ and letting C # programs invoke it through P / Invoke. Or perhaps in C #, and let C ++ applications call this through COM interaction. This assumes, of course, that your C ++ applications are native, not C ++ / CLI.

+1
source share

I have never tried this, but theoretically it should work. As I mentioned in my comment, use the UDP port on the loopback device. Then all processes can read and write from / to this socket. As you say, the messages are small, so they should fit into each package - maybe you can look at something like Google protocol buffers to create structures or just mem copy the structure into the sending packet, and on the other end, considering all this on the local host , you have no problems with setup, such as network order. To support different types of messages, make sure that the general header can be checked for the type so that you can be backward compatible.

2cents ...

+1
source share

I think another important consideration is performance, what level of messages we are talking about and not. processes? In any case, you rely on the "host", which allows communication needs, whether it is a user service or the provided system (channels, message queue, etc.).

If you don’t need to track and request past messages, I think you should think about a dead simple service that opens a named pipe, allowing all other processes to either read or write to it as PipeClients. If I'm not mistaken, it checks all the items in your list.

0
source share

What you are looking for is Mailslots!

See CreateMailslot: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365147(v=vs.85).aspx

0
source share

All Articles