简体   繁体   中英

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).

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM