0

i want to write a program in two different languages java and c++ that needs a dynamic and interactive communication between its c++ component and java component.i know there is jni and jna for invoking native methods in java but i do not think this method is appropriate for my purpose.

for example : say a program that its User Interface is written in c++ and other in java, i do not think that communicating these two component can be done through jni and jna. for example Open Office is written in java and c++. i searched the internet and find some method for Inter-process communication like shared memory , pipe, signals, Message passing , ... but i don not know that Inter-process communication is what i need. it seems ipc is for communicating software in two different process but my program all is one process(am i right?!)

so my question is : how the programs that its component is written in different language communicate together? and how i can achieve this?

mehrdad
  • 51
  • 1
  • 7
  • You can use sockets but then you have to de/serialize you data. I've seen people use a temp file as a buffer for passing data between programs. I have no experience with this, but it is just a suggestion. Here is a link on msdn about communication https://msdn.microsoft.com/en-us/library/aa365574%28v=vs.85%29.aspx – Jesse Laning Mar 23 '15 at 16:28
  • i need very low latency , so socket is not good. – mehrdad Mar 23 '15 at 16:30
  • "i know there is jni and jna"..."but i do not think this method is appropriate for my purpose." Why do you think so? JNI seems to be exactly what you're looking for. "i do not think that communicating these two component can be done through jni and jna" Again, why do you think so? – eerorika Mar 23 '15 at 16:32
  • Just wondering: how do you think you can run some binary ... and a Java JVM in the same process? Meaning: of course you have TWO processes, and of course you need inter-process communication. – GhostCat Mar 23 '15 at 16:32
  • @mehrdad You could use shared memory but doing that in java might be difficult so you would probably have to use jni or jna anyway. – Jesse Laning Mar 23 '15 at 16:34
  • thank guys! i have little experience in jni and jna, the projects that i used these techs we just invoked some native method and done, but if ui is in c++ it need to response an accept , i dont know maybe it can be used. – mehrdad Mar 23 '15 at 16:39
  • EddyG , i did not know " can run some binary ... and a Java JVM in the same process" !, – mehrdad Mar 23 '15 at 16:40
  • i just want to know the standard way that this kind of communication is done. – mehrdad Mar 23 '15 at 16:41

1 Answers1

3

JNI has been exactly created for the purpose that you are describing; why exactly is it not "what you need"?

One other option: message brokers with implementations for different languages, like http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol

But as you are stressing the latency, this might not be for your.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 2
    I am working in an BIG IT enterprise. We are using AMQ. Good enough?! Seriously - you should **not** rely on other people's opinions. You should **sit** down and analyse your requirements in depth; and then you should turn to the internet, search for available solutions; and for each of them, again **you** should learn about the pros and cons of each option to understand how each option aligns with your requirements. Selecting option A because somebody tells you that some "enterprise" is using it ... might work out; but you will not learn much acting so. – GhostCat Mar 23 '15 at 16:39
  • 3
    Using google, it took me 3 seconds to find http://activemq.apache.org/activemq-real-time.html ... but you preferred to spent 10+ seconds to write down another question. That is what I just told you: if you want to become a serious software engineer - then start digging into the material yourself! (and asking here is NOT digging ) – GhostCat Mar 23 '15 at 16:49