简单的跨平台的程序来处理单声道的沟通? [英] Simple cross-platform process to process communication in Mono?

查看:125
本文介绍了简单的跨平台的程序来处理单声道的沟通?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,将在Linux,Mac和Windows上运行,并需要应用程序来简单的字符串消息发送到对方的能力(在一个操作系统)单应用程序。

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出来了,因为我不希望有这是一个额外的要求。
插槽通信似乎是很难,窗户似乎不允许连接权限。映射文件
内存似乎没有在单声道的支持。命名管道
似乎没有在单声道的支持。
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?

推荐答案

我写的这个单-dev邮件列表上。一些通用的进程间消息系统进行了审议,其中的DBus,System.Threading.Mutex类,WCF,远程处理,命名管道...的结论是基本的单不支持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.

我只能够想象三种可能的解决方案。所有有其缺点。也许有更好的解决方案可用,或者只是为特定目的更好的解决方案,或也许的存在一些跨平台的第三方库,你可以在应用程式(我不知道)。但这些是最好的解决方案,我已经能够到目前为止找到:

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:


  • 开启或建立在已知位置的文件,用专用锁。 (FileShare.None)。每个应用程序试图打开该文件,做它的工作,并关闭文件。如果无法打开,Thread.sleep代码(1),然后再试一次。这是一种贫民窟,但它的工作原理跨平台,提供跨进程互斥。

  • 套接字。首先应用程序监听localhost上,一些高编号端口。第二应用程序尝试侦听该端口,无法打开(因为一些其他进程已经它),因此第二处理将消息发送到第一处理,这是在该端口上已侦听。

  • <利>如果你有机会到一个事务型数据库,或消息传递系统(SQS,RabbitMQ的,等等)使用它。
  • 当然,你可以发现你是在哪个平台上,然后利用该平台上的任何工作。

  • Open or create a file in a known location, with exclusive lock. (FileShare.None). Each application tries to open the file, do its work, and close the file. If failing to open, Thread.Sleep(1) and try again. This is kind of ghetto, but it works cross-platform to provide inter-process mutex.
  • Sockets. First application listens on localhost, some high numbered port. Second application attempts to listen on that port, fails to open (because some other process already has it) so second process sends a message to the first process, which is already listening on that port.
  • If you have access to a transactional database, or message passing system (sqs, rabbitmq, etc) use it.
  • Of course, you could detect which platform you're on, and then use whatever works on that platform.

这篇关于简单的跨平台的程序来处理单声道的沟通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆