IPC between Java and C applications

前端 未结 4 1269
故里飘歌
故里飘歌 2021-01-20 08:18

I have 2 applications, one written in C and the other in Java, that suppose to run on the same machine. What is the best way to implement an IPC between them?

best m

相关标签:
4条回答
  • 2021-01-20 08:54

    You can use either named sockets or network sockets for this purpose..

    0 讨论(0)
  • 2021-01-20 09:18

    I would use Sockets over loop back to start with. This allows you to send text or binary data and cleanly handle when one process starts or dies. The latency is about 20-50 micro-seconds depending on what you are doing with the data and how much you send.

    Sockets are platform independent and can be use in pure Java. There are millions of examples and tutorials available for Java.

    0 讨论(0)
  • 2021-01-20 09:18

    I've found that the simplest approach is to exec the native program from java, and then communicate via the process input and output streams. This only works for ASCII communication though, which in most cases is fine. This approach works across platforms. If the applications are launched independently of eachother, then files or sockets are both cross-platform approaches and will work with binary data if desired.

    There's always JNI or JNA, but these are typically best suited to a tight couplin between java and native code.

    0 讨论(0)
  • 2021-01-20 09:19

    I have never tried it, but Java does have support for memory mapped files http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/MappedByteBuffer.html which would give you ability to share objects between C and Java apps. Synchronizing access might be challenging because I don't think Java has direct access to OS-level IPC synchronization primitives.

    0 讨论(0)
提交回复
热议问题