2

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

I have a C process which uses an ipc message queue to send and receive data. I also have a Java application which needs to send and received messages to/from that C process, so it needs access to that queue.

I've been searching for a way to do this and I think JNA (java natice access) could be a solution. The problem is that, apparently, I need a DLL so I can map and use the methods I need (msgget, msgsnd,msgrcv,msgctl), but I don't know which DLL I should load. I'm quite new at this so I'm feeling lost.

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

Thanks in advance.

BlackVegetable
  • 12,594
  • 8
  • 50
  • 82
Anne
  • 189
  • 1
  • 4
  • 16
  • Its the same DLL the C process has to load. (ideally exactly the same DLL) I would assume its part of Windows. – Peter Lawrey Aug 08 '12 at 18:08
  • 1
    First of all, thanks for your help. The thing is I'm not sure of understand. To use that methods in a C program I just need to include "sys/ipc.h" and "sys/msg.h" but I don't know if those header files are part of a DLL (I haven't used DLL until now) or, like victorsavu3 has said, I'm going to have to use JNI because they're just wrappers. – Anne Aug 08 '12 at 18:52
  • Either way you use the same DLL. IMHO using JNI might be easier in this case and it will be certainly much faster which I assume it part of the point of using IPC. – Peter Lawrey Aug 08 '12 at 18:55
  • Searching a little more I found this "http://en.wikipedia.org/wiki/C_POSIX_library". Since the includes appear in the list, I started a very small example loading the C POSIX library. Now I have an error, but I will post it later. Thanks again. – Anne Aug 09 '12 at 07:57

3 Answers3

1

If that is an option, you could change the C process to use a different way of communication. In my experiences Sockets are the least troublesome way of communicating between c and java programs/processes.

John Smith
  • 2,282
  • 1
  • 14
  • 22
  • Thanks for your answer. The problem is I can't change the message queue and use sockets. At least, not at this moment. – Anne Aug 08 '12 at 18:28
0

The use of JNA is perfectly legal, but somehow tricky.

This post "Java POSIX IPC" may have some clues as to how to do that in Java or using Java Libraries.

Community
  • 1
  • 1
Filipe Fedalto
  • 2,540
  • 1
  • 18
  • 21
  • Thanks for your answer. I had found http://www.bmsi.com/java/posix/ this morning while I was looking for answers but it seems to be an abandoned project isn't it? I mean, the last update was 3 years ago, that's why I was afraid of trying to use it. – Anne Aug 08 '12 at 18:36
0

If you can find depend.exe (I know VS 2005 has it), it can show you the functions each dll exports. Run it on your c program to see where the functions are coming from, if they are real you can use JNA. The functions might actually be just wrappers and if so you need to use JNI

victorsavu3
  • 195
  • 1
  • 6