简体   繁体   English

在两个C#程序之间发送大量数据

[英]Sending large volume of data between two C# programs

I am currently working on a C# (I could use python also) plug-in for two separate programs that need to communicate. 我目前正在为一个需要通信的两个独立程序开发一个C#(我也可以使用python)插件。 In the first first program, I deconstruct 3D geometry into edges, points, normals, etc. Then I send all of this data to my plug-in in my second program to be rebuilt. 在第一个第一个程序中,我将3D几何体解构为边缘,点,法线等。然后,我将所有这些数据发送到我的第二个程序中的插件中进行重建。 Ideally this would happen as fast as possible to keep things i "real time". 理想情况下,这将尽可能快地发生以保持“实时”。

Currently, I am converting my data with JSON, and writing the JSON to the disk. 目前,我正在使用JSON转换数据,并将JSON写入磁盘。 Then my second program watches for file changes, and then reads the file and uses the JSON data. 然后我的第二个程序监视文件更改,然后读取文件并使用JSON数据。

By far the biggest bottle neck of my entire plugin is the read/write process. 到目前为止,我整个插件的最大瓶颈是读/写过程。 There has to be a faster way than writing to a file. 必须有一种比写入文件更快的方法。

There are several ways to use interprocess communication. 有几种方法可以使用进程间通信。
The most well known are used between different machines: WCF(.NET 3.5) and Remoting(.NET 2) 最着名的是在不同的机器之间使用:WCF(.NET 3.5)和Remoting(.NET 2)

For on-machine communication you can choose to use Named pipes or Memory mapped files. 对于机上通信,您可以选择使用命名管道或内存映射文件。

Memory mapped files are similar to your solution in that they use the page file as a backup. 内存映射文件与您的解决方案类似,因为它们使用页面文件作为备份。

I think the Named pipes solution is the most convenient: You set up a "server" stream and wait for some "client" to connect. 我认为命名管道解决方案是最方便的:你设置一个“服务器”流并等待一些“客户端”连接。 Then you transfer the data just as you would through any other stream. 然后就像传输任何其他流一样传输数据。

Here's NamedPipeServerStream . 这是NamedPipeServerStream
And this is NamedPipeClientStream . 这是NamedPipeClientStream
The code example there pretty much covers it. 那里的代码示例几乎涵盖了它。

I think WCF with named pipes would do the job, you just have to create transfer objects, which will be serialized and it will be all done by WCF automagically, or you can just prepare your existing objects to be transfered by named pipe with not really big overhead. 我认为使用命名管道的WCF可以完成这项工作,你只需要创建传输对象,它将被序列化,它将全部由WCF自动完成,或者你可以准备你的现有对象被命名管道转移而不是真的很大的开销。 Using json would be nice but it creates additional layer, and with WCF you transfer objects which can be used right away without translation by json. 使用json会很好但它会创建额外的图层,并且使用WCF传输可以立即使用的对象而无需json进行转换。 (Really they are translated to xml but you are not doing it by yourself so it is better then you could do with parsing json I think). (实际上它们被翻译成xml,但你不是自己做的,所以它比你解析json更好,我认为)。

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

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