简体   繁体   中英

Java <-> C Bridge

I'm working on a application which has Java web interface hosted on Glassfish server and C kernel which is implemented as Linux daemon.

My biggest problem right now is how to make Remote Procedure Calls. I need to call functions and methods in both directions. These are the possible solutions that I can think of:

  1. Use Java Native Interface and network sockets to implement RPC.
  2. D-Bus - as far as I know DBus can be used for RPC between Java and C.

I want to use the most basic way without using external libraries or frameworks. Is it possible directly to call functions/methods between Java and C using only sockets? The OS that I use is Centos.

Is there more elegant way to connect the two languages?

Without external libraries, only sockets remain. But I would classify DBus as an external library, wouldn't you?

If the C program can use sockets, there is no need for Java Native Interface. The Java code can open sockets from Java , calling the sockets the C code listens to.

If you allow DBus, maybe you should consider the plethora of networking and RPC protocols which have libraries for both C and Java. (Again, no need to use JNI.)

Going the DBus way, look at the Java documentation and the tutorial .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM