Sending / receiving data between two different programs

I am looking for some tips here.

I am working on an application where the main processing (stored on the server) is done in C ++ and the GUI (front-end) is done in Python. These two programs will communicate with each other. Python will send the files necessary for the C ++ program to work, and provide the C ++ program with some data to work with them. Then the server will access the processed data.

Would it be better to use Sockets? I thought about this using text files, but, missing this idea, instead it just saves the data as a .txt file so that it can be opened in future instances. Also, if I were using sockets, would there be a conflict using Python / C ++?

Any help or advice would be greatly appreciated.

+4
source share
4 answers

Try ZeroMQ

ØMQ ( ZeroMQ, 0MQ zmq) concurrency. , , , TCP . N-to-N , , pub-sub, -. , . - , . API- . ØMQ - iMatix LGPLv3.

++ , :

//
//  Hello World server in C++
//  Binds REP socket to tcp://*:5555
//  Expects "Hello" from client, replies with "World"
//
#include <zmq.hpp>
#include <string>
#include <iostream>
#ifndef _WIN32
#include <unistd.h>
#else
#include <windows.h>
#endif

int main () {
    //  Prepare our context and socket
    zmq::context_t context (1);
    zmq::socket_t socket (context, ZMQ_REP);
    socket.bind ("tcp://*:5555");

    while (true) {
        zmq::message_t request;

        //  Wait for next request from client
        socket.recv (&request);
        std::cout << "Received Hello" << std::endl;

        //  Do some 'work'
#ifndef _WIN32
        sleep(1);
#else
    Sleep (1);
#endif

        //  Send reply back to client
        zmq::message_t reply (5);
        memcpy ((void *) reply.data (), "World", 5);
        socket.send (reply);
    }
    return 0;
}

Python:

#
#   Hello World client in Python
#   Connects REQ socket to tcp://localhost:5555
#   Sends "Hello" to server, expects "World" back
#
import zmq

context = zmq.Context()

#  Socket to talk to server
print "Connecting to hello world server…"
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")

#  Do 10 requests, waiting each time for a response
for request in range(10):
    print "Sending request %s …" % request
    socket.send("Hello")

    #  Get the reply.
    message = socket.recv()
    print "Received reply %s [ %s ]" % (request, message)
+4

, , , , , .. ( )

0

Would therefore it be better to use Sockets?

. , . , , , ( ), , - .

. Python - c c

, .

0

Python ++ .

If you want to send it between these applications on the same computer, you can use file association. http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx Keep in mind the best ways to do this.

But, if you want to send it between two computers, definitely use TCP Sockets

-1
source

All Articles