简体   繁体   English

Java Application和C ++ Application之间的通信

[英]Communication between Java Application and C++ Application

I'm trying to write a plugin for a Java Application. 我正在尝试为Java应用程序编写一个插件。 The plugin should be able to tell the Java Application that new events have been recognized (Observer Design Pattern, Polling ... thats not the point). 该插件应该能够告诉Java应用程序已经识别出新事件(观察者设计模式,轮询......这不是重点)。 The problem is that the events are tracked gestures coming from a Microsoft Kinect controller (I´m using C++ and the Microsoft Kinect SDK because I have to). 问题是事件是来自Microsoft Kinect控制器的跟踪手势(因为我必须使用C ++和Microsoft Kinect SDK)。 So that means I have to communicate between the Java Application and my Kinect Application. 这意味着我必须在Java应用程序和我的Kinect应用程序之间进行通信。 I thought of something like an adapter design pattern where the Java application is "including" the interface (c++ header file, dll etc.). 我想到了类似于适配器设计模式的东西,其中Java应用程序“包括”接口(c ++头文件,DLL等)。 First I thought of JNI but then I have to write a DLL that will be used on both application sides, right? 首先我想到了JNI,但后来我必须编写一个将在两个应用程序端使用的DLL,对吧? Another thing I thought of was to provide the gesture data via a protocol like UDP (or something more lightweight?). 我想到的另一件事是通过UDP(或更轻量级的东西?)等协议提供手势数据。 The last thing I heard of was to write a COM+ assembly ... but to be honest my knowledge about COM+ is rather little. 我听到的最后一件事是写一个COM +汇编......但说实话,我对COM +的了解相当少。

JAVA APPLICATION << ----- ??? ----- >> KINECT APPLICATION

May be you should have a look at google's Protocol Buffers . 也许你应该看看谷歌的协议缓冲区

Since you are considering JNI . 既然你在考虑JNI I'd suggest you refer to this IBM tutorial . 我建议你参考这个IBM教程

JNI allows the java application to call c/c++ methods and vice-versa. JNI允许java应用程序调用c / c ++方法,反之亦然。

Also have a look at this question , if you are calling java from c++. 如果你从c ++调用java,也要看看这个问题

I have found some examples such as here , here and here which recommend you either used a shared memory structure or else use sockets. 我找到了一些例子,例如这里这里这里建议你使用共享内存结构或者使用套接字。

I think that in this case, letting your programs communicate through sockets would be the best idea since your applications will not be that tightly coupled, so you just need to expose an IP, a port and a set of commands. 我认为在这种情况下,让你的程序通过套接字进行通信是最好的主意,因为你的应用程序不会紧密耦合,所以你只需要暴露一个IP,一个端口和一组命令。

According to this it seems possible to create a C++ server on the Kinect, but other than that I can't say much since I have never worked on Kinect related projects. 根据一点,似乎可以在Kinect上创建一个C ++服务器,但除此之外我不能说太多,因为我从未参与过Kinect相关项目。

JNI (Java Native Interface) allows the java application to call c/c++ 
methods.

All this requires that we have a means of communicating (Integrating Java 
with C++) between Java and C++. This is provided by the JNI (Java Native 
Interface).

For a practical example of using the JNI.

Calling native methods from Java see this url
https://www.javaworld.com/article/2077513/learn-java/java-tip-17--integrating-java-with-c--.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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