Results 1 to 8 of 8

Thread: [C++, Java] How to share data between two programs

  1. #1
    Join Date
    Dec 2009
    Beans
    403

    [C++, Java] How to share data between two programs

    Hi,

    I would like to share data between a program A written in C++ pr C and another program B written in Java. The two program can be located in different networks. How can I do this? The simplest idea is to use a shared file where one program writes and the other program reads. The problem is how to manage the read/write conflicts. For example if the program A is writing the file how can I assure that the program B does not read the file? Is there a better way than a shared file?
    Thank you

  2. #2
    Join Date
    Mar 2010
    Location
    Metro-ATL; PM free zone.
    Beans
    8,676
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: [C++, Java] How to share data between two programs

    Well, there are lots of ways to have programs communicate over a network. The language use doesn't matter, provided they speak the same protocol. Going over the internet means that you want to use a secure channel, right? No traffic between 2 programs should be transmitted without encryption, IHMO.

    * REST API with XML, JSON or other data packages
    * XML API
    * sockets
    * CORBA (a little old school now)
    * or any number of other methods can be used. REST is what all the new kids use these days.

    To prevent conflicts, use a session ID and client authentication. That way the server doesn't get confused between different clients. I'm certain there are existing libraries that handle these things, though I haven't written any C/C++ for this in a long time and never needed to communication outside the LAN. With Python, Perl, Ruby, using REST is built-in and fairly easy.

  3. #3
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: [C++, Java] How to share data between two programs


  4. #4
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,264
    Distro
    Kubuntu

    Re: [C++, Java] How to share data between two programs

    There's also GMSEC. You can use one of the provided middleware services (e.g. Bolt), or use a COTS product (e.g. WebSphere), or even FOSS such as ActiveMQ.

    Let me know if you have any questions.

  5. #5
    Join Date
    Dec 2009
    Beans
    403

    Re: [C++, Java] How to share data between two programs

    Thank you for the answers. Now suppose that I have the following requirement. A more complicated scenario in which there a pseudo-server (C++ program) and many pseudo-client (Java programs). I have written pseudo since that I don't want to establish authentication/acknowledgement between the two programs. The pseudo-server is not aware of the existence of the pseudo-clients. The information need to be exchanged via files. In this case how can I share information avoiding conflicts?
    Thank

  6. #6
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,163
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: [C++, Java] How to share data between two programs

    Normally you can open the files with exclusive rights, so that only one of the sides can be dealing with a given file (read or write) at any time. But sharing data via files looks really like a bad design. A better solution would be to use some form of light database.

  7. #7
    Join Date
    Dec 2009
    Beans
    403

    Re: [C++, Java] How to share data between two programs

    Quote Originally Posted by ofnuts View Post
    Normally you can open the files with exclusive rights, so that only one of the sides can be dealing with a given file (read or write) at any time. But sharing data via files looks really like a bad design. A better solution would be to use some form of light database.
    I know that this is not good design. It's the reason for which I have asked here for other solutions. I'm not expert of database, but if I decide to use it how can manage multi-user without authentication? The quantity of data that the two programs need to exchange is limited.
    Thank

  8. #8
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,163
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: [C++, Java] How to share data between two programs

    Quote Originally Posted by erotavlas View Post
    I know that this is not good design. It's the reason for which I have asked here for other solutions. I'm not expert of database, but if I decide to use it how can manage multi-user without authentication?
    EIther:
    • you use the DB authentication: each user is given an id/pwd to the DB, and the software gets these from the user and uses them to access the DB on the user's behalf.
    • the code uses some secret/hidden usr/pwd to access the DB, and the DB contains a table of users/passwords. The client software requires an id/pwd from the user and checks it against the DB.
    • you can also envision a 3-tier solution with some web server in front of the DB (so that the real DB access is done only by that server, after cheicnk user credentials)


    Quote Originally Posted by erotavlas View Post
    The quantity of data that the two programs need to exchange is limited.
    This makes the DB soltuion even more palatable.

    This said, you seem to have a problem to solve, think up solutions, that lead to 2-level problems to which to think up solutions, that lead to 3-level problems ... and then you ask us about the latter. Metaphorically, you may be painting yourself in a corner, and just asking us for a better brush... Maybe that if we are told about the original problem we can give better directions (why hsould one of the be written in C++?). Futhermore all this has the smell of a reinvented wheel, and I cannot convince myself that your original problem is that much different from other real-life problems for which the appropriate software already exists. Darwinism somehow applies to application design... those you see everywhere must have some merit...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •