Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new in NamedPipe concept on Linux/Centos 7. I want to implement read write funtions between my Windows and CentOS PC using NamedPipe. I have created a NamedPipe on CentOS PC using mkfifo function and written some text on this pipe.

On other side(Windows PC), I want to read that text written on NamedPipe. I have tried to use both CreateFile and open function for Pipe handle. I have successfully got the handle of Pipe but ReadFile and read function failed.

What I have tried:

I have created a NamedPipe on CentOS PC using mkfifo function.

int res; res = mkfifo("fifo1",0777);//creates a named pipe with the name fifo1

and written some text on this pipe.

Now I want to perform Read and write operations on NamedPipe on my Windows PC. I will really appreciate if any one can help me out with that issue.
Posted
Updated 4-Feb-23 3:00am
Comments
Richard MacCutchan 1-Feb-23 7:47am    
Each pipe needs to be able to talk across the network so you need some way of providing the network addresses in the pipe names.
Rick York 1-Feb-23 10:56am    
Are you sure that pipes between Linux and Windows machines are compatible? I am not at all certain they can work together and everything I have read says they can not. I think you would be better off using a socket connection because those CAN work between different operating systems.

Named pipes are only used for communication between processors on the same computer. They do not provide any network capabilities. Consider that on your linux system you create a named pipe:
C
int pipe = mkfifo("fifo1", 0777);

When your program executes this, it will create a directory entry in the current working directory:
prwxr-xr-x 1 k5054 k5054 0 Feb  1 10:32 fifo1

You can now read/write to the file handle "pipe" in the current program and other programs, on the same system, may call open() on the file path and read/write to communicate with the first program.

Leaving aside any Windows/Linux issues, how then might a program running on another linux system access "fifo1" on the first system? You might be able to do so if you are using a shared network filesystem (e.g. NFS of SAMBA), but otherwise there's no mechanism to reach across the network to open the named pipe (N.B I have not tried to read/write a pipe over NFS, so cannot confirm it will work).

To communicate between systems you would normally use IP sockets, either TCP or UDP. There are other network technologies out there, but by far the most widely used is IP. It's a lot more complex than simple interprocess communications, but there are any number of tutorials that google can find for you.
 
Share this answer
 
Comments
Rick York 1-Feb-23 13:28pm    
Your first two sentences are incorrect for windows. They CAN be used between machines and I have done it myself. Here is what Microsoft has to say about them : https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-use-named-pipes-for-network-interprocess-communication. I have no idea about using them with Linux.
Bruno van Dooren 3-Feb-23 12:11pm    
On Windows, Named Pipes can be used for communications between systems and it's a much better alternative than direct TCP / UDP because they are tied in with Windows security so not only can the server restrict access, but the server can -depending on system config, security settings and client's approval- impersonate the client for passing client-server calls, or checking group membership of the calling token.
After reading the documentation on linux FIFO, I think it should not be able to interconnect with windows named pipes over the network because windows puts objects in \\.\pipe\ namespace, and linux doesn't have a special namespace for FIFO(windows namepipe).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900