I know Java can act as a client for reading/writing named pipes, but I need another program which acts as a server.
In this case the program I am communicating with must act as the client, rather than the server. Is it possible for Java to act in server mode for named pipes?
EDIT: In named pipes (Windows) there are client and server modes. A server must first be established before a client can connect to it. I have a legacy application which acts as a 'client', this means that it connects to what it assumes is an already established named pipe. I have a new java application which I would like to have communicate with this legacy app using named pipes. I have only found examples of how to use Java named pipes in connection to previously established named pipes.
A pipe is a section of shared memory that processes use for communication. The process that creates a pipe is the pipe server. A process that connects to a pipe is a pipe client. One process writes information to the pipe, then the other process reads the information from the pipe.
Named pipes can be used to provide communication between processes on the same computer or between processes on different computers across a network. If the server service is running, all named pipes are accessible remotely.
A named pipe is a Windows specific interprocess communication method that allows processes on the same or different systems to communicate with each other.
To create an instance of a named pipe by using CreateNamedPipe, the user must have FILE_CREATE_PIPE_INSTANCE access to the named pipe object. If a new named pipe is being created, the access control list (ACL) from the security attributes parameter defines the discretionary access control for the named pipe.
Well on linux and mac you can always have java emit to the console one line at a time. Example:
In one terminal window to this:
mkfifo myPipe
java -jar mydataserver.jar > mkfifo
In a second terminal window do this:
while read line; do echo "What has been passed through the pipe is \
${line}"; done<myPipe
Yes, you can create named pipe on the Java server using JNA library https://github.com/java-native-access/jna
It is clearly shown in the following test: https://github.com/java-native-access/jna/blob/master/contrib/platform/test/com/sun/jna/platform/win32/Kernel32NamedPipeTest.java
API of JNA wrapper is the same as Win32 hence you will be able to use all the features and power of named pipes on Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With