我该如何使用这些 IPC 技术?

发布于 2024-08-14 16:50:37 字数 706 浏览 7 评论 0原文

我记得当时使用 C 和 win32 时我有很多 IPC 技术。到目前为止,我还没有在 .NET 中遇到过它们,也没有在 C 之外见过它们,所以我想问我如何实现这些进程间通信技术?

  1. 共享/全局内存。只需分配可以由另一个进程在没有任何信号的情况下更改的 RAM。

  2. 窗口消息。我记得使用 SendMessage 并使用 WM_USER + N 并在我触摸共享内存时告诉另一个应用程序,要求它更改文件或设置,有时告诉其他应用程序我输入了一些按键来充当宏,因为我有时感到懒惰。 p>

  3. 动态数据交换。我尝试过,但始终无法使其发挥作用。据我记得(警告这可能是完全错误的),您将自己注册到全局消息或事件,另一个应用程序(通常是您的)将发送消息,并且两个左右的应用程序可以相互通信,发布消息,您可以进行集成以这种方式在两个应用程序之间。我很想知道是什么取代了它。

还有一些命名管道,我知道它们仍然在使用和看到。我记得有人推荐 IPC 套接字,但我从来不喜欢这样做,而且我知道它仍然存在,并且可以在需要时使用。

我还错过了什么以及什么取代了这种技术?我知道有全局互斥锁,这很酷。我仍在寻找一种在两个应用程序之间发送消息的现代方式(第 2 点)。我一直想知道是否存在某种不在管道中的 FIFO 队列。就像 Windows 消息一样,除了我可以推送数据(如 1k),而不是每次发送消息并分配全局内存。

-编辑-碰撞。目前该主题仍然与我相关。

I remember back in the day while using C and win32 i had a number of IPC techniques. So far i haven't ran into any of them in .NET or seen them outside of C so i thought i ask how might i do these inter-process communication techniques?

  1. Shared/Global memory. Simply allocate ram that can be change by another process without any signal.

  2. Window message. I remember using SendMessage and using WM_USER + N and told another app when i touched shared memory, ask it to change files or settings and sometimes told other app that i typed in some keystrokes to act as a macro because i sometimes feel lazy.

  3. Dynamic Data Exchange. I tried but never could get this to work. From what i remember (warning this could be completely wrong) you register yourself to a global message or event and another app (usually yours) would send message and the two or so apps can communicated to each other, post message and you can have integration between two apps this way. I'm very interested to know what replaced this.

There are also named pipes which i know are still used and seen. And i remember people recommending sockets for IPC but i never liked to do that and i know that still exist and can be used if i need.

What else did i miss and what replaced this techniques? I know there are global mutex which is cool. I'm still looking for a modern way to send messages between two apps (point 2). I always wondered if there was some kind of FIFO queue that wasn't in a pipe. Like a windows message except i can push data (like 1k) instead of sending msgs and allocating global memory each time.

-edit- bump. this thread is still relevant to me at the moment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一向站在原地 2024-08-21 16:50:37

在 .NET 中,您可以使用:

  1. 命名管道
  2. 内存映射文件
  3. WCF

共享/全局内存在 .NET 中不容易实现,您必须对 Win32 调用进行互操作并固定托管内存,以​​避免它被 GC 移动。

显然,窗口消息仅在有窗口(可见或隐藏)时才起作用。 .NET 应用程序不应使用此技术。

DDE - 不要使用。

In .NET you can use:

  1. Named pipes
  2. Memory mapped files
  3. WCF

Shared/global memory are not easily achievable in .NET, you'd have to do interop to Win32 calls and pin managed memory to avoid it being moved by the GC.

Window messages obviously only work when you have windows, either visible or hidden. This technique should not be used by the .NET applications.

DDE - don't use.

哽咽笑 2024-08-21 16:50:37

即使您知道套接字,但并不真正喜欢它,我确实记得在某处读过,在 Windows 上通过本地主机的套接字确实有一个快捷路径,并且可以优化到单个内存副本的级别。然而,在我的一生中,我找不到我在哪里读到的内容,所以也许其他人可以链接到来源。

这样做的缺点是我确实相信您必须有一个活动的网络代码才能建立连接,但一旦建立它实际上不会使用整个 TCP/IP 堆栈。

另请注意 Andrei 的帖子,我测试了内存映射文件(如果没记错的话,本机仅在 .net 4.0 中添加),但我遇到了一些麻烦。它可能会起作用,但没有太多文档,您仍然需要写出两个应用程序如何同步读取和写入,无论是用于通知的信号量,还是查看文件中某个位置的紧密循环。

就我个人而言,在我正在开发的应用程序上,我通过本地主机使用套接字,到目前为止还没有遇到任何大规模的性能或安全问题。但这会回到你的设计目标和安全要求是什么。

Even though you are aware of sockets, but don't really like it, I do recall reading somewhere that on Windows a socket through localhost does have a shortcut path, and may be optimized to the level of a single memory copy. However, for the life of me I can't find where I read that so maybe someone else can link to the source.

The downside of this is I do believe you have to have an active network code to establish the connection, but it won't actually use the entire TCP/IP stack once established.

Also a note for the post by Andrei, I tested Memory Mapped Files (which native is only added in .net 4.0 if memory serves) and I was having some trouble with it. It will likely work, but there isn't much documentation, and you still sort of need to write out how the two application synchronize read's and writes, whether it be a semaphore for notification, or a tight loop looking at a location in the file.

Personally, on the APP I'm developing i'm using sockets through localhost, and so far have not encountered any massive performance or security issues. But it will come back to what are you're design goals and security requirements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文