aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes How to communicate Java application with C++ application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How to communicate Java application with C++ application" Watch "How to communicate Java application with C++ application" New topic
Author

How to communicate Java application with C++ application

Ana Gonzalez
Greenhorn

Joined: Aug 08, 2012
Posts: 2
Hello everyone,

It's quite difficult for me to explain what I need to implement, so I really hope to be able to do it.

I have a C process which uses an ipc message queue to send and receive data. And I have a Java application which needs to send and received messages to/from that C process, so it needs to access to that queue. I've been searching a way of doing this and I think JNA (java natice access) could be a solution. The problem is that, aparently, I need a DLL so I could map and use the methods I need (msgget, msgsnd,msgrcv,msgctl), but I don't know what DLL I should load. I'm quite new at this so I'm feeling lost.

Is there another way of communicate this two applications using message queues? Or is JNA a good solution and I only need to find the correct DLL to load??

Thanks in advance

Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Ana, you're combining some complex stuff into one problem. May I suggest that you break it up into smaller parts? One way to do that would be to have all of your IPC and interprocess communication done in C++, and use the Java Native Interface ("JNI") to let your Java code call some C++ routines to communicate with the rest of your C++ code. JNI is a bit messy at first, but you do get used to it.

If you have Core Java Volume II (8th edition), read Chapter 12. Or you might try this online tutorial.

I do a lot of work with the JNI, so feel free to ask questions here; I'll help if I can.
Ana Gonzalez
Greenhorn

Joined: Aug 08, 2012
Posts: 2
Thank you very much for your answer.
Finally, I was able to make it run. I found out that "sys/ipc.h", "sys/msg.h" and "sys/types.h" are part of the C POSIX Library (http://en.wikipedia.org/wiki/C_POSIX_library), so I loaded it

--------------------------------------------------------------------------

--------------------------------------------------------------------------

After that, there was a couple of problems due to the mappings needed. But everything is running now.

Again, thank you so much for your advice.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to communicate Java application with C++ application