简体   繁体   English

在Windows上通过管道进行Java / C ++通信

[英]Java/C++ communication via pipe on Windows

I have two separate programs, one in Java and one in C++, both running on Windows. 我有两个独立的程序,一个是Java,另一个是C ++,都在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. 到目前为止,我们正在使用这种笨拙的写入文本文件并在另一方面读取它们的解决方案,生产者在完成写入时会生成一个.lock文件,消费者会在完成阅读后将其删除...我说,尴尬。

If we were on *nix, we would use a pipe using popen() on the C++ and RadomAccessFile on the Java side. 如果我们在* nix上,我们将在C ++上使用popen()并在Java端使用RadomAccessFile。 It seems to work well. 它似乎运作良好。

What can we do on Windows? 我们可以在Windows上做什么? Can we use named pipes? 我们可以使用命名管道吗?

Thank you. 谢谢。

I'd recommend sockets for IPC if you are using a mix of Java and C++. 如果您使用Java和C ++混合,我建议使用IPC插槽。 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 不过,我会指示你 SO帖子...好像你可以使用命名管道在.NET一侧的RandomAccessFile在Java端: http://v01ver-howto.blogspot.com/2010/04/ HOWTO使用,命名管道到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 看看谷歌的协议缓冲区: http//code.google.com/apis/protocolbuffers/docs/overview.html

This provides a serialization mechanism between Java and C++. 这提供了Java和C ++之间的序列化机制。

And then google for a C++ stream implementation for sockets and send messages between java and C++ via TCP. 然后google获取套接字的C ++流实现,并通过TCP在java和C ++之间发送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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