What is the best way to pass information from java to c++?

后端 未结 8 1754
太阳男子
太阳男子 2021-02-07 04:59

I have a java application I need to pass some info to a C++ program. It has been suggested that I use some simple socket programming to do this. Is this the best way? If not

8条回答
  •  离开以前
    2021-02-07 05:27

    More information needed (but a good question).

    Are these two separate programs running at the same time?

    If not, and the Java program needs to call a C++ library, the JNI answer is a good solution, but it won't really work across processes.

    In the case of processes, you really do need to find a way to communicate across processes...a simple solution (probably not the best, but I don't know your exact situation) would be to have a binary file that is written to and read from...just don't forget to beware of race conditions! Sockets could also work, but if your programs communicate a lot, it might be a bit of a hog on CPU power.

提交回复
热议问题