Simple cross-platform process to process communication in Mono?(在 Mono 中处理通信的简单跨平台流程?)
问题描述
我正在开发一个将在 Linux、Mac 和 Windows 上运行的 Mono 应用程序,并且需要应用程序(在单个操作系统上)相互发送简单字符串消息的能力.
I'm working on a Mono application that will run on Linux, Mac, and Windows, and need the ability for apps (on a single os) to send simple string messages to each other.
具体来说,我想要一个单实例应用程序.如果尝试启动第二个实例,它将改为向已运行的单个实例发送消息.
Specifically, I want a Single Instance Application. If a second instance is attempted to be started, it will instead send a message to the single instance already running.
DBus 已退出,因为我不想让它成为额外的要求.套接字通信似乎很难,因为 Windows 似乎不允许连接权限.Mono 似乎不支持内存映射文件.Mono 似乎不支持命名管道.Mono 似乎不支持 IPC.
DBus is out, as I don't want to have that be an additional requirement. Socket communication seems to be hard, as windows seems to not allow permission to connect. Memory Mapped Files seems not to be supported in Mono. Named Pipes appears not to be supported in Mono. IPC seems not to be supported on Mono.
那么,有没有一种简单的方法可以将单个机器上的字符串消息发送到在每个操作系统上运行的服务器应用程序,而不需要权限或其他依赖项?
So, is there a simple method to send string messages on a single machine to a server app that works on each os, without requiring permissions, or additional dependencies?
推荐答案
我在 mono-dev 邮件列表上写过这个.考虑了几个通用的进程间消息系统,包括DBus、System.Threading.Mutex类、WCF、Remoting、Named Pipes……结论基本是mono 不支持 Mutex 类(适用于线程间,不适用于进程间)和 没有任何可用的平台不可知.
I wrote about this on the mono-dev mailing list. Several general-purpose inter-process messaging systems were considered, including DBus, System.Threading.Mutex class, WCF, Remoting, Named Pipes... The conclusions were basically mono doesn't support Mutex class (works for inter-thread, not for inter-process) and there's nothing platform agnostic available.
我只能想象三种可能的解决方案.都有自己的缺点.也许有更好的解决方案可用,或者可能只是针对特定目的更好的解决方案,或者也许存在一些可以包含在应用程序中的跨平台 3rd 方库(我不知道.)但是这些是迄今为止我能找到的最佳解决方案:
I have only been able to imagine three possible solutions. All have their drawbacks. Maybe there's a better solution available, or maybe just better solutions for specific purposes, or maybe there exist some cross-platform 3rd party libraries you could include in your app (I don't know.) But these are the best solutions I've been able to find so far:
- 使用排他锁在已知位置打开或创建文件.(文件共享.无).每个应用程序都会尝试打开文件、执行其工作并关闭文件.如果打开失败,Thread.Sleep(1) 并重试.这是一种贫民区,但它可以跨平台工作以提供进程间互斥锁.
- 套接字.第一个应用程序在本地主机上侦听,一些高编号的端口.第二个应用程序尝试侦听该端口,但无法打开(因为其他进程已经拥有该端口),因此第二个进程向已在该端口上侦听的第一个进程发送消息.
- 如果您有权访问事务数据库或消息传递系统(sqs、rabbitmq 等),请使用它.
- 当然,您可以检测您在哪个平台上,然后使用该平台上的任何功能.
这篇关于在 Mono 中处理通信的简单跨平台流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Mono 中处理通信的简单跨平台流程?
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01