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 th开发者_开发百科at" can educate me about the pros and cons of the options.
- Shared memory
- Pipe, stdin/stdout, etc.
- Custom data structure over plain socket (probably UDP) (this question)
- Messages over plain socket, could be Google protocol buffer, Thrift, JSON, etc. (this answer, among others)
- Java RMI with C++ RMI server (this question)
- 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).
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.
I'd go with option 4. I'd skip 5. 2 would be clunky.
We're talking passing the numerics as plain text, yes?
精彩评论