简体   繁体   中英

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

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

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.

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