7

I'm working on a project where I'll have one application in C# and another one in Python. The C# application will continuously analyse stream of data and raise a flag each time something interesting is detected. So each time there will be an event, my Python application will have to read it and continues with it own process, while other flags will continue being sent. As you understand the C# app won't wait for the Python one to finish its computation before sending another flag.

So I was wondering if it was possible to create a sub/pub (C# being the Publisher, and Python the Subscriber), if yes how can I do it, and do you think it's a good idea? I'm pretty new in this field, so could you tell me if there are other possibilities?

Thx for your help.

5
  • 1
    Any reason why sockets won't work?
    – JeffS
    Commented Jul 7, 2012 at 1:05
  • 1
    Is there any compelling reason you want to do this over 2 separate platforms?
    – spender
    Commented Jul 7, 2012 at 1:19
  • Thank you all for your answers. Both Redis and sockets were what I think I could use, now I'm more confident about it.
    – ssx
    Commented Jul 7, 2012 at 1:20
  • @spender Different people work in this project and they all want to keep their language of predilection. So the colleague working on the hardware uses C, the one who analyses the data coming from the sensors will use C# and I'll use Python for the rest. Comments about this fact are welcome.
    – ssx
    Commented Jul 7, 2012 at 1:26
  • If you want to connect two applications together, sockets and even better a common data mark up language like xml or json will solve a lot of your problems. You want to find a middle ground between the two platforms and the best is to go with something that can be read/created on both sides. Commented Jul 7, 2012 at 3:09

3 Answers 3

5

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

2

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:

2
  • thank you very much, I'll try them all to see which one is more convenient.
    – ssx
    Commented Jul 7, 2012 at 11:30
  • questioner seems to be on windows, as C# is regarded. on windows, there is no need to get extra permissions to use sockets. your term, 'Access Level' is quiet ambiguous. it could be ACL or integrity level on windows. but both are no problem in using sockets - do you need some administrative permissions to open Chrome? for security, I don't understand what you intended to say but, it is clearly unacceptable to hear pipes and sockets have different security considerations on local usage. Socket is suggested as it's much more faster than pipes.
    – Laie
    Commented Jun 29, 2016 at 5:19
0

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()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.