views:

316

answers:

2

Hi,

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

+2  A: 

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

Polaris878
Polaris, thanks. I've seen that post and the corresponding blog post. I even implemented the Java side while a colleague implemented named pipes in C++. The problem is that Java complains with a file not found exception because "\\\\.\\pipe\\testpipe" does not exist.Now, when running on a Mac, the \\.\pipe\testpipe merely creates a file and runs smoothly. But we're not deploying on *nix, unfortunately enough.
Warlax
+2  A: 

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.

Peter Smith
We've done this using our own protocol.... thank you.
Warlax