我正在开发一个应用程序,该应用程序具有托管在 Glassfish 服务器上的 Java Web 界面和作为 Linux 守护程序实现的 C 内核。
我现在最大的问题是如何进行远程过程调用。我需要双向调用函数和方法。这些是我能想到的可能的解决方案:
- 使用Java Native Interface和网络套接字来实现RPC。
- D-Bus - 据我所知,DBus可以用于Java和C之间的RPC。
我想使用最基本的方式,而不使用外部库或框架。
是否可以仅使用套接字直接在 Java 和 C 之间调用函数/方法?我使用的操作系统是 Centos。
有没有更优雅的方式来连接两种语言?
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:
- Use Java Native Interface and network sockets to implement RPC.
- 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?
发布评论
评论(1)
没有外部库,只剩下套接字。但我会将 DBus 归类为外部库,不是吗?
如果C程序可以使用套接字,则不需要Java Native Interface。 Java 代码可以从 Java 打开套接字,调用 C 代码侦听的套接字。
如果您允许 DBus,也许您应该考虑大量的网络和 RPC 协议,它们都有 C 和 Java 库。 (再次强调,无需使用 JNI。)
采用 DBus 方式,请查看 Java 文档 和 < href="http://dbus.freedesktop.org/doc/dbus-tutorial.html">教程。
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.