简体   繁体   English

2路跨流程通讯

[英]2-way Cross Process Communication

I am working on a project that i want to have a plugin-sandbox like System, However i am having issues working out 2-Way Real time Cross Process Communication. 我正在一个项目中,我希望有一个像System这样的插件沙箱,但是我在解决2-Way实时跨过程通信时遇到了问题。 At first i thought of WCF, as it can pass object Metadata, but then soon realized that the Service Client model of WCF will pose an issue. 起初,我想到了WCF,因为它可以传递对象元数据,但是不久之后,我意识到WCF的Service Client模型将带来问题。 but before i lay down all my ideas and questions here is what i have planned out. 但是在我提出所有想法和问题之前,这里是我计划的内容。

I want to have a host application that will do most of the work, let us call this host.exe, host.exe will host the main application logic for the program, as well as the launching, executing, and killing of Plugins. 我想要一个可以完成大部分工作的主机应用程序,让我们称之为host.exe,host.exe将承载程序的主要应用程序逻辑,以及启动,执行和终止插件。 Plugins will be hosted via a Plugin Proxy that will host them via MEF, so we will call it proxy.exe. 插件将通过插件代理托管,而代理代理将通过MEF托管它们,因此我们将其称为proxy.exe。 The proxy.exe will load plugin dlls and host them in a secluded environment that will isolate faults and if the plugin fails it will kill the proxy and not the application. proxy.exe将加载插件dll并将其托管在一个僻静的环境中,该环境隔离故障,如果插件失败,它将杀死代理而不是应用程序。 The Host and the Proxy need to communicate in real time in both directions and because there are going to be multiple proxy hosts it would be best to be able to pass object data. 主机和代理服务器需要双向双向实时通信,并且由于将有多个代理服务器主机,因此最好能够传递对象数据。

so that is the basic idea of what i want. 这就是我想要的基本想法。 I was thinking of several ways to do this. 我正在考虑几种方法来做到这一点。 the first being WCF, however i figured that the way WCF works it would be difficult if not impossible for the server of the service to send the client a request/command. 第一个是WCF,但是我认为WCF的工作方式很难,即使不是不可能,服务的服务器也无法向客户端发送请求/命令。 the next idea what to use TCP, and have the host be a TCP server and develop a messaging protocol that i can use to communicate, however that poses an issue as i do not have the luxury of the WCF metadata and passing complex class information would be down right insane. 下一个想法是什么使用TCP,并让主机成为TCP服务器并开发一个我可以用来通信的消息传递协议,但是这带来了一个问题,因为我没有WCF元数据的奢侈性,并且会传递复杂的类信息疯了

Through all my research i have came up with issue after issue after issue, it would much appreciated if anyone is able to suggest a solution to this issue. 通过我的所有研究,我逐个问题地提出了建议,如果有人能够提出解决方案,将不胜感激。 Thank you. 谢谢。

Interprocess communication (IPC). 进程间通信(IPC)。 Which maybe should called cross-process communication (CPC) is a known MS/Windows specific concept. 可以将其称为跨进程通信(CPC)是已知的MS / Windows特定概念。

More about it here 在这里了解更多

In the past I've used RPC and Windows Pipes (which is used also in SQL server for transferring large data-sets/results) 过去,我使用过RPC和Windows Pipes(在SQL Server中也用于传输大型数据集/结果)

You can always try another method of communication, WCF, Sockets, Pub/Sub Messaging; 您可以随时尝试使用其他通信方法,即WCF,套接字,发布/订阅消息。 example, TibcoRv (which locally would bypass sockets). 例如TibcoRv(在本地将绕过套接字)。 I find these to be a bit of an overkill. 我觉得这些有些过分了。 but could be perfect for your requirement. 但可能非常适合您的要求。

My solution for this would likely be remoting. 我对此的解决方案可能是远程处理。 I dont know if WCF does this the same way. 我不知道WCF是否这样做。 but remoting can be configured with text and servers can be setup to remote to an object at will. 但是可以使用文本配置远程处理,并且可以随意将服务器设置为远程对象。

I want to warn you up front. 我想提前警告你。 The project I am mentioning is from quite a while ago so this may be out dated information (WCF may do the same thing or it may not, My company has not required any WCF work from me.) 我要提到的项目是从很早以前开始的,所以这可能是过时的信息(WCF可能做同样的事情,或者可能做不了,我的公司不需要我做任何WCF工作。)

I remoted my objects from the client to the server. 我将对象从客户端远程部署到服务器。 I would run the server (actually on a separate machine) then using tcp remoting, all the objects I wanted would be declared into that application. 我将运行服务器(实际上是在单独的计算机上),然后使用tcp远程处理,我想要的所有对象都将声明到该应用程序中。

Now here is the fun part. 现在,这是有趣的部分。 that remoted object used non remoted delegate objects. 该远程对象使用了非远程委托对象。 I would initialize the object (remoted) and the server would create it. 我将初始化对象(远程),然后服务器将创建它。 Then I would initialize another (Interface Typed) object local and attach it to the remote object. 然后,我将在本地初始化另一个(接口类型)对象,并将其附加到远程对象。

When the remote object wanted to communicate to me it would send serializable information to me and I would construct that into more objects or commands. 当远程对象想要与我通信时,它将向我发送可序列化的信息,然后将其构造为更多的对象或命令。 Whatever was needed... (possibly more remote objects) 无论需要什么(可能是更多的远程对象)

In any rate. 无论如何。 One server and multiple remote objects would be sent back and forth with a CommonInterface.dll with all the standard interface objects defined in it. 一台服务器和多个远程对象将与CommonInterface.dll及其定义的所有标准接口对象一起来回发送。

This was for all intents and purposes a blind plugin setup that any application wanting to get information to or from my server would be able to implement and handle their classes as long as the interfaces matched. 出于所有目的和目的,这是一个盲目的插件设置,只要接口匹配,任何想要从我的服务器获取信息或从我的服务器获取信息的应用程序都将能够实现和处理其类。 (with serializable command data) (带有可序列化的命令数据)

If the plugin (client) crashes then the application (server) would not have to suffer. 如果插件(客户端)崩溃了,那么应用程序(服务器)就不会受到影响。 It would just wrap all communication to that plugin in a try catch and the remoted object would have some sort of time to live or ping style release mechanism. 它只会将与该插件的所有通信包装在try catch中,而远程对象将有一定的生存时间或ping样式释放机制。

I dont really know what your scenario is going to be like with the sandboxing but this may accomplish what you are asking. 我真的不知道沙盒的情况会怎样,但这可能会满足您的要求。

here is a .net remoting chat server. 这是一个.net远程聊天服务器。

http://www.codeproject.com/KB/IP/dotnetchatapplication.aspx http://www.codeproject.com/KB/IP/dotnetchatapplication.aspx

This is the same type of project I build my first time with remoting. 这与我第一次使用远程处理构建的项目类型相同。 and I evolved it into my server plugin architecture. 然后将其演化为服务器插件架构。 The difference between my use and yours is that the server was my client was the main application using the server and yours the server will be the main application allowing multiple clients to plugin. 我和您的使用之间的区别在于,服务器是我的客户端,是使用服务器的主要应用程序,而您的服务器将是允许多个客户端插入的主要应用程序。

In my opinion, I advice you use different application domains, an communicate with plug-ins using interfaces, and a real proxy object references. 我认为,建议您使用不同的应用程序域,使用接口与插件进行通信以及真实的代理对象引用。 Do not use different processes, you can achieve plug-ins isolation through application domain isolation, because exceptions do not cross application domain boundaries unless specified. 不要使用不同的过程,可以通过应用程序域隔离来实现插件隔离,因为除非指定,否则异常不会跨越应用程序域边界。

As an alternative, you can use deprecated technologies, as .NET Remoting, for tje cusom marshaling and transparent proxy object creation. 作为替代方案,您可以使用不赞成使用的技术(如.NET Remoting)进行脚本封送处理和透明代理对象创建。

In my opinion, WCF is too heavy and too far from real-time processing 在我看来,WCF太重了,与实时处理相差太远

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM