简体   繁体   English

通过网络连接从C#向非托管C ++发送数据

[英]Sending data over a network connection from c# to unmanaged c++

I have ac# dll that needs to send a quite complex object over the network to an unmanaged c++ process. 我有一个ac#dll,需要通过网络将一个非常复杂的对象发送到一个不受管理的c ++进程。 I'm aware that there are a number of ways to do this but was wondering if anyone can recommend the best fit. 我知道有很多方法可以做到这一点,但我想知道是否有人可以推荐最合适的方法。 Important points to note: 注意事项:

  1. It is critical that the c# process is informed if data is not received by the c++ process. 如果c ++进程未接收到数据,则通知c#进程至关重要。 Preferably I'd like as reliable a method of transferring the data as possible. 优选地,我希望有一种可靠的传输数据的方法。
  2. Unfortunately I'm also under pressure to deliver the packets as quickly as possible so ultimately some trade off will be required between reliability and performance. 不幸的是,我也承受着尽快交付数据包的压力,因此最终需要在可靠性和性能之间进行权衡。
  3. The c# object that represents the data is likely to change. 表示数据的c#对象可能会更改。 This is a third party object which we have no control over. 这是我们无法控制的第三方对象。 Ideally I'd require some dynamic mechanism in the c++ process to handle these changes with as minimal impact as possible. 理想情况下,我需要在c ++流程中采用某种动态机制来以最小的影响来处理这些更改。 Worst case scenario would be if we have to recompile the code everytime the object data changes. 最糟糕的情况是,每次对象数据更改时我们都必须重新编译代码。
  4. Id rather avoid using third party libraries if possible. 如果可能的话,我宁愿避免使用第三方库。

Any help would be much appreciated. 任何帮助将非常感激。

As far as I understand about your question, you might mean LAN or WLAN by "network". 据我对您的问题的理解,您可能用“网络”来表示LAN或WL​​AN。 so, I suggest to use UDP/IP on both sides. 因此,我建议双方都使用UDP / IP。 and for "It is critical that the c# process is informed if data is not received by the c++ process", you need to handle it manually (eg via an acknowledge packet per receiving a packet or bunch of packets). 对于“如果c ++进程未接收到数据,则通知c#进程至关重要”,则需要手动进行处理(例如,通过每个接收到一个数据包或一堆数据包的确认数据包)。

there are a lot of samples available over internet for UDP/IP unde 'socket programming': like one here: http://www.abc.se/~m6695/udp.html 互联网上有很多用于UDP / IP的“套接字编程”的示例:就像这里的一个: http : //www.abc.se/~m6695/udp.html

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

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