Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 864
Peter Penzov Avatar asked Feb 06 '12 08:02

Peter Penzov


1 Answers

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.

like image 128
Prof. Falken Avatar answered Nov 10 '22 16:11

Prof. Falken