Daisetsu
Daisetsu

Reputation: 4976

Can Java act as a Named Pipes server?

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.

Upvotes: 10

Views: 2474

Answers (2)

jreznot
jreznot

Reputation: 2773

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.

Upvotes: 1

Steve Owens
Steve Owens

Reputation: 899

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

Upvotes: 1

Related Questions