interprocess C# python real time

≡放荡痞女 提交于 2019-11-29 11:01:27
Ria

Simplest way is PIPE communication. another simple way that not suggested is SOCKET programming. Pipes and Named pipes are good solution to communicate between different processes (over different programming languages). SOCKET programming is like this but may need more Access Level and may be less security.

other type of IPCs seems be unusable.

see for more info:

Redis pub/sub is awesome... or ZeroMQ.

You may use our aktos-dcs and aktos-dcs-cs libraries. I have successfully used these libraries in production in order to make an RFID Reader (from Impinj) communicate with (actually, integrated in) our telemetry system. The RFID reader has a C# API and we are heavily using Python in our telemetry system.

The simplest test case is a pinger-ponger application, and here is how it looks like with these libraries:

pinger.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using aktos_dcs_cs;

namespace pinger
{
    class Pinger : Actor
    {
        public void handle_PingMessage(Dictionary<string, object> msg)
        {
            Console.WriteLine("Pinger handled PingMessage: {0} ", msg["text"]);

            string msg_ser = @"
                    {""PongMessage"": 
                        {""text"": ""this is proper message from csharp implementation""}
                    }
                ";
            System.Threading.Thread.Sleep(2000);
            send(msg_ser);
        }

    }


    class Program
    {
        static void Main(string[] args)
        {
            Pinger x = new Pinger(); 
            Actor.wait_all(); 
        }
    }
}

ponger.py:

from aktos_dcs import *

class Pinger(Actor):
    def handle_PingMessage(self, msg_raw):
        msg = get_msg_body(msg_raw)
        print "Pinger got ping message: ", msg['text'], (time.time() - msg_raw['timestamp'])
        sleep(2)
        self.send({'PongMessage': {'text': "Hello ponger, this is pinger 1!"}})

if __name__ == "__main__":
    ProxyActor()
    pinger = Pinger()
    pinger.send({'PongMessage': {'text': "Hello ponger, this is STARTUP MESSAGE!"}})

    wait_all()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!