Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 709
Daisetsu Avatar asked Aug 08 '13 20:08

Daisetsu


People also ask

What is a pipe server?

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.

What uses named pipes?

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.

What is locator named pipe used for?

A named pipe is a Windows specific interprocess communication method that allows processes on the same or different systems to communicate with each other.

How do you make a named pipe in Windows?

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.


2 Answers

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
like image 61
Steve Owens Avatar answered Sep 29 '22 04:09

Steve Owens


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.

like image 30
jreznot Avatar answered Sep 29 '22 06:09

jreznot