Java/C++ communication via pipe on Windows
I have two separate programs, one in Java and one in C++, both running on Windows. We need to do bidirectional interprocess communication between the two.
Up until now, we were using this awkward solution of writing to te开发者_Go百科xt files and reading them on the other side, where the producer would generate a .lock file when it's done writing and the consumer would remove that when it's done reading... like I said, awkward.
If we were on *nix, we would use a pipe using popen() on the C++ and RadomAccessFile on the Java side. It seems to work well.
What can we do on Windows? Can we use named pipes?
Thank you.
Take a look at google's protocol buffers: http://code.google.com/apis/protocolbuffers/docs/overview.html
This provides a serialization mechanism between Java and C++.
And then google for a C++ stream implementation for sockets and send messages between java and C++ via TCP.
I'd recommend sockets for IPC if you are using a mix of Java and C++. Sockets seem like a more robust solution than writing/locking a shared file :).
However, I'll point you to this SO post... It seems like you can use named pipes on the .NET side and RandomAccessFile on the Java end: http://v01ver-howto.blogspot.com/2010/04/howto-use-named-pipes-to-communicate.html
Give that a shot... it looks promising
精彩评论