Communication between a C# and Python application hosted on the same machine - c#

We're working on a project that requires us to interface with a specific set of hardware; one set can be controlled very easily using C#, the other of which is natively programmed using Python. Part of the project involves getting the hardware running on Python to communicate with the hardware running through C#, and unfortunately, due to time constraints, we aren't able to create a set of C# or Python software to control the other set of hardware.
The set of hardware running on Python is completely event based, in that we can program functions that are called when certain conditions are met by the hardware. Our thought was to modify the C# application controlling the other set of hardware to host the Python application (using something like Application.Run()), then program the Python functions to propagate relevant data to the C# application as the events come in from the hardware.
We're considering using a socket connection to handle communication between the two, as both C# and Python are fairly simple to get working that way (or so our Python guy claims). The biggest concern with this that we have is if there will be any issues with the fact that both programs will be hosted on the same machine. If this won't be an issue, we would probably end up using a shared library such as 0MQ
We've also done some research into the following areas:
Pipes / Named Pipes
Message Queues
Shared Memory
Basically we want to know which method of these (or any others) will be the easiest to implement with these languages, and which will give us the best performance. We are concerned only with speed and accuracy of the data (ie, if using network packets, one that will drop the least). Security is not a concern.
Ideally, there should be one data stream going from the Python application to the C# application, and two data streams going from the the C# application to the Python application. The host machine will be running Windows 7. I can give additional information as needed.

One option is to try IronPython. Since IronPython is a .NET language, communicating with C# code should be easy.
It seems worth looking into how hard it would be to get your existing Python code running on IronPython.

Related

Communication between C# and C++ application

I have just start learning about WCF that can help me for the communication between two different platform application. I have also created one simple application for the communication but both client and service are written in C#. I want to know how I can establish a C++ and C# application so that they communicate to each other. Thanks in advance
this question seems very wide to me, the thing is since you are in windows, and the C# and C++ applicattions will be running simultaneously, you have to thing in the specific requeriments of you appliccation.
For example, I had a Server in C# wich recived some data, that had to be processed in C++ and then returned to the sender, so, since the C# and C++ process were in the same computer I used a File Mapping method, for example.
Indepently of the language, what you have to make sure, is that the data you send, wen you recive it in the other process, that should be able to be understood.
Here is a link for more info in wnidows
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx

What is the fastest way to have C# communicate with Python?

I need a way for c# to communicate with an arbitrary version of Python. The user passes in a path to Python, so they can choose any version they want. I need to be able to pass a string to Python, and get back a float. This needs to happen several thousand times. Right now i'm just using standard in/out, but it seems to be very slow. Is there any faster way to do this?
Typically, the "best" way to handle this type of scenario is to use IronPython instead of having the user supply their own Python runtime.
You can also use Python for .NET, but this again will tie you to a specific version of Python.
If you control what's called in Python, but need arbitrary versions of python, you may be able to use a common messaging service. One option would be to setup an IPC channel via pipes, which are supported in Python and .NET. This would provide fast C#->Python->C# communication while keeping the process separate.
If you need arbitrary versions and installations of python, than executing and fetching information via the shell process may be the only option.
Very fast is using zmq, libraries are available for both, C# and Python, can talk across network, in some situations is faster then plain TCP.
E.g. iPyhton is using it for internal inter-component communication.
My StackOverflow answer shows Lock server implemented over zmq which could be used to serve C# too.

Can C# Mono create tunnel interfaces multiplatform?

I haven't been able to find a solution answer on this for the past 2 days:
Can C# Mono, or a supported third party framework, be used to create and manage layer 2 tunnel over a virtual interface across the 3 major platforms (OSX, Windows, Linux)?
At a high-level an application like Hamachi or Tunngle would be a real world example for what I'd like to achieve at a basic level.
The intention behind this question is whether it would be possible to write effective cross-platform code or whether I would have to resort to platform-specific code to implement the virtual interfaces.
That depends. Since L2TP is actually accomplished using UDP datagrams, there's no reason why you can't implement it in C#. However, integrating it with the operating system (as a virtual interface driver etc.) is more or less impossible - I'd expect the only real way would be to have a small native wrapper that calls the managed code that does most of the work.
In other words - you can write Hamachi in .NET just fine. Writing the Hamachi Network Adapter is the tricky part. Also, if you just want to add L2TP capabilities to your applications, there's no problem (instead of TcpClient/UdpClient etc., you'd just use your own class that communicates with your L2TP class). However, integrating it to the IP infrastructure does require you to write a driver, which is usually a native-only territory.
It might be that there are some ready-to-use solutions that have the virtual network adapter which can call DLLs, but I'm not aware of any. A very unsafe way would also be to create hooks on Socket calls, but I'm not going to elaborate since that's extremely tricky and a bad idea overall :D
In other words, you have the option to use a hybrid approach - have the minimal native drivers for all the platforms you want to support, and let them call your managed library to do all the real work - the managed library can then be platform independent (as long as Mono is supported there :)).
Now, each OS probably has its own VPN client, which you could concievably use from .NET. However, that also means that your application will have to be able to support each of these OSes and their different VPN clients separately - and that will be tricky.
If you want to go the way of writing your own network interface driver, a good way to start on Windows is the Driver Development Kit, which has some sample source code for NIC drivers. Windows uses NDI (http://en.wikipedia.org/wiki/Network_Driver_Interface_Specification), which has some support even on *nix family of OSes, so it might be possible to do this relatively easily - but don't forget, you're still writing a driver. Unless you have significant experience with C/C++/ASM and OS kernels and driver models, you're probably out of your league here. This is the stuff that leads to BSODs :)
There's also some related technologies like TDI (Transport Driver Interface) or WFP (Windows Filtering Platform) which could be used to do all this in user-space, rather than kernel/driver-space. However, those are Windows technologies. You'll have to find the equivalents on the other OSes you want to support, and you'll have to do some magic to make it all work in one cross-platform application. And while doing all this, you want to maintain performance - which requires very careful programming in .NET (it's easy to write reliable code in .NET, but it's harder to get cutting-edge performance. C/C++/ASM is quite the opposite - it's relatively easy to do things fast, but reliability suffers).

mpi packet for c# paralleling program

I want to make my C# program in parallel on two host over lan, I know I should use the mpi language, but really I don't know which packet should I install that can connect to another computer, and run a C# program parallel, I just want to run it on two computer,my Os is window7,32 bit operating system,and I am programming with vs2010.
You should install something like MPI.NET - it provides .NET class wrappers around the MPI API and allows easy use from C#. Be aware though that the C# API is not part of the MPI standard and therefore might (and probably will) differ between different vendors. Unfortunately MPI.NET has been dead for years, probably due to lack of interest in using MPI with C# on behalf of the .NET developers community.
Another option would be to utilise P/Invoke to call the MPI functions from the MS-MPI DLLs directly. This won't work very well due to the differences in the memory models of MPI (especially when it comes to non-blocking operations) and .NET.

ZeroMQ C++ to C# communication

My current project involves building a high speed framework for communications across different OSs and remote systems for computer vision applications where the various components communicate using ZeroMQ sockets. This works fine in Standard C++ (Non-Cli).
I have recently found a use-case where I need to interface with an application coded in C#. Having compiled and run the "Hello World" example from the guide (On localhost) with clrzmq 2.2.2. I cannot get the two programs to communicate (One in C++ one in C#).
The C# server receives a request from the C++ client but nothing happens after that, it just seems to hang, which would indicate a problem with the C# response. Replacing the C# server with a C++ one compiled from the guide works fine.
Does anybody have any experience of getting C++ apps to talk to .NET using ZMQ? I would be grateful for any help, as this is not covered in any documentation I have been able to locate.
That is likely to be an application bug. We have a program like that running without issues. C# to c++.

Categories

Resources