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 ?
6/5/2022 2:01:11 PMKetan Lalcheta
13 AnswersNew Answer
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
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
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 🤣
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
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.
Hello, the named pipes are on linux os or windows?
I am on windows
Thanks arnold etaba
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
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.
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
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 ?
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 ?