What are windows IPC methods

房东的猫 提交于 2019-12-01 06:41:23

Some common ones are:

  • Named Pipes. Fairly easy to implement.
  • Shared Memory. A little more work but may be a little bit faster (at least in my testing).
  • Sockets. This is fairly simple and very portable but not as high performance. But it is sure nice if you suddenly want to be able to communicate with a process running on a different machine.
Georg Fritzsche

COM is the de-facto standard IPC mechanism for Windows-focused applications nowadays.

It allows access across language-barriers, solves the binary interface compatibility problem, does transparent marshalling for you and has different threading models.

sharptooth summarized some facts nicely here.

Don't forget Remoting, for higher level possiblities in .NET

For simple, fast communication, you might consider Mailslots. They are quite easy to use. You interact with them like you would a file.

Mailslots are most appropriate when you want to broadcast commands to multiple recipients, or receive messages from multiple producers and your design can tolerate the occasional lost message. Named pipes, mentioned above, are better suited for single process-to-single-process, guaranteed-delivery IPC.

The good news

  • They are very simple to implmement
  • They support asynchronous operation
  • They can be used even given Windows Process Isolation. This means you can use them to communicate between different user sessions (e.g. with Windows Services)
  • They can broadcast messages to the entire domain by opening a mailslot to "\*\mailslot[path]name". When you write to a mailslot with a name like that, it will send it to every mailslot of that name on every machine in your domain

The bad news

  • Only 424 bytes can be transferred over the network. More data can be transferred locally
  • They are UDP based, so only use them if losing a message from time to time is okay
  • Occasionally (particularly on multi-processor systems), messages can be delivered slightly out of order

Many samples are available, but I don't have enough rep yet to post more than the one on CodeProject in C++

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!