This is a question about inter process communication via stdin/stdout.
The problem is I have a COM library, which I wasn't able to use with any Java-COM bridge (one particular function always causes core dump). But I was able to use it from a C++ program.
So I decided to make a wrapper server program in C++ to make those calls for me, and communicate with it from Java via stdin/stdout, but I'm facing a problem here. I've decided to use protobufs for communicating messages, the main problem is reading input on the C++ side. I need a method, that will block until a certain amount of bytes is written to stdin for it to read.
The idea was to use google's protobufs, and set up communication like this:
- C program starts an infinite loop, blocking on STDIN input, waiting to get 4 bytes in, which would be the length of the incoming message.
- Then it blocks to get the whole message (raw byte count is known)
- Parse the message with protobuf
- Do work
- Write output to stdout (probably in the same manner, prepending the message with the number of bytes incoming)
- Java clinet reads this using DataStream or something like this and deciphers using protobufs as well
Setting up this two way communication turned out to be quite a lot harder, than I would have thought, thanks to my lack of knowledge of C++ and Windows programming (I compile it using MSVS2013 Community, and there are so many windows specific marcos/typedefs from all this COM code).
Is there some 3rd party lib, that can make creation of such a simple server, well, actually, simple?
PS: can be C, can be C++, I just need it to run on Windows.