Named pipes between Java and C / C ++ programs

I am thinking of using a named pipe in Windows to communicate between two applications written in Java and C. I usually use a socket connection for this, but now I need to cancel this idea and find a new solution.

I read that a named pipe in java can only be seen inside the JVM - is that true? Is there a way to establish a named pipe between two applications in different languages?

If not, what technology do you advise?

+2
source share
3 answers

To create a Windows named pipe in Java, you have to resort to using JNI to invoke your own WINAPI functions.

You can create a named pipe in C ++ and use it in Java by opening it as a file in the channel namespace after creating it.

+3
source

Named pipes are much more difficult to get than using sockets. Conceptually, they are simpler. However, making them reliable and reasonably fault tolerant is much more difficult than for sockets.

I would suggest you reconsider sockets, this is for communication between processes. Can you explain why you cannot use sockets? The reason I'm asking is because named pipes actually used sockets on the loop in reality.

A named pipe is an OS design. You can create a named pipe in your OS, and then you can get it as if it were a file using Java and C or any other program. Communication between processes through a file is very difficult to obtain the right (if not impossible). For example, you do not suspect that when you write to a named pipe, everything reads something, unless you create your own flow control protocol. (It is very difficult to check in all cases)

You may have heard of PipedInputStream and PipedOutputStream, and these classes can only be used in the same process (which makes them pretty useless)

EDIT: If you want an independent view of the most common and possibly the most reasonable way to send data, I suggest you try Google.

java sockets - 2,210,000 hits java named pipes - 90,000 hits 

Thus, perhaps sockets are 25 times more intelligent than named pipes. (and more supported as there are more textbooks and people who have experience with them)

+2
source

You can simply start an external process in Java and connect to it.

  // Execute command String command = "ls"; Process child = Runtime.getRuntime().exec(command); // Get pipes from process InputStream in = child.getInputStream(); OutputStream out = child.getOutputStream(); InputStream error = child.getErrorStream(); 
0
source

All Articles