Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the good alternatives for communication between local C++ and Java programs?

By "local" I mean both run in the same subnet, in most cases the same host/VM, therefore some standard cross-network cross-platform RPC mechanisms like SOAP, XML-RPC, CORBA, etc. seem unnecessary.

The payload is mainly numerical (mostly tabulated) data with some small amount of meta data (for example available data services, data description/type, etc.) from C++ to Java, and console/scripted UI events from Java to C++. So the C++ program acts like the server and Java program the client.

I can enumerate several options (mostly from searching this wonderful site) but I've never used or seen one in a real-world heavy-duty situation, so I really hope someone who's "been there, done that" can educate me about the pros and cons of the options.

  1. Shared memory
  2. Pipe, stdin/stdout, etc.
  3. Custom data structure over plain socket (probably UDP) (this question)
  4. Messages over plain socket, could be Google protocol buffer, Thrift, JSON, etc. (this answer, among others)
  5. Java RMI with C++ RMI server (this question)
  6. JNI (some answers in this question)

I'm pretty sure I've missed many options. Thank you all for your help!


Edited: I forgot to mention that performance is not a major concern as the data throughput is not expected to be huge (server is heavily database-bound), but it would be important to know if one option stands out to be much faster or slower. For example, I suppose nothing beats shared memory (if done right).

like image 276
std_colon-colon_ex Avatar asked Oct 12 '10 01:10

std_colon-colon_ex


2 Answers

Options 3 and 4 are used in real-world heavy-duty situations.

Options 1,2,6 do not reach another host.

Option 5 is probably too troublesome for the non-Java side.

I'd go with Option 4, because Option 3 is too low-level (unless Option 4 turns out to be too slow). Choose your favourite cross-platform light-weight messaging protocol from the ones you enumerated. Those are all "battle-tested" and have libraries for most languages.

like image 161
Thilo Avatar answered Nov 11 '22 23:11

Thilo


I'd go with option 4. I'd skip 5. 2 would be clunky.

We're talking passing the numerics as plain text, yes?

like image 34
Tony Ennis Avatar answered Nov 12 '22 00:11

Tony Ennis