+ 3
Namedpipe in multiple process
Hi I have a system which has two threads... One thread is to process on the input and other thread is to collect all input ... Input thread function has thread function running infinite time... This has namedpipe which reads input from other process... This works fine for me as of now.. What to do now if there are two different process which can give input to namedpipe running into the thread function ? How to handle namedpipe reading if both process gives different input at same time ?
13 Réponses
+ 2
Apparently, whenever a client process opens up a new pipe to write to your server thread, a new instance of the pipe is allocated to the client process, so if multiple clients decide to write to your pipe, they will each have their own independent instances of the named pipe, hence making it thread safe.
https://stackoverflow.com/questions/30284666/is-callnamedpipe-on-windows-thread-safe
+ 2
For servicing multiple processes that can give different inputs at same time to your named pipe, you can have a main loop in your server program , which will spawn a new thread for every new client connection, to service that particular client connection then return. This is made possible because, as earlier pointed out, whenever a process connects to your named pipe, it gets its own independent instance of the pipe to communicate on.
https://docs.microsoft.com/en-us/windows/win32/ipc/multithreaded-pipe-server
+ 1
It's a good choice actually. But from the little background i have about them from unix, they are generally used to allow processes on the same host to communicate together.
But let's just find out if we can make them work easily over a network, it part of leaning too i guess 🤣
+ 1
Finally done..... it was issue to create named pipe , nothing on client side...
I was not allowing remote client while creating named pipe... something simillar to PIPE_ACCEPT_REMOTE_CLIENTS should be added to name pipe creation.
Also access control list with full access to all should be passed to namedpipecreate
With these two changes on server side, it worked
+ 1
Wow, that's cool man.
Now that I'm thinking about it, such a problem could have been troubleshooted to occur on server side, by monitoring if the namedpipe packets from the client reach the server but are dropped on arrival with a tool like wireshark.
Congrats once more.
Im curious about what kind of fun stuffs one could build with that.
0
Hello, the named pipes are on linux os or windows?
0
I am on windows
0
Thanks arnold etaba
0
I tried code shared in article but it seems working on same computer only ... Client and server not working from different computers.....
For server :
\\\\.\\pipe\\mypipe
For client:
\\\\mycomp\\pipe\\mypipe
mycomp is ip address of server which I am able to ping from the client... Tried with computer name also but not working
While running client on different system result into createfile failure with last error code as 2
0
Not very sure about that, but you should also try to bind the server pipe to server ip address.
Server:
\\\\mycomp\\pipe\\mypipe.
I'll give it a try too today.
0
I tried as well but no success...
Infact this server and client pipe I had originally taken from below link :
https://stackoverflow.com/questions/41380071/c-named-pipes-over-network-invalid-name-error
0
Ok thanks for pointer. By the way friend, if i may ask, what advantage or requirement pushes you to use named pipes over a network instead of sockets for example ?
0
I am new to such type of programming...so just exploring....
I just need to develop something kind of server and multiple client with thread safety... is named pipe not good choice ?