I'm in a big mess and kindly need your advices(and it's kind of urgent too)..
I have written a Named Pipe client in java where the Named Pipe server is in C++ and cannot be modified. In the client, i have used java's "RandomAccessFile" to create a bidirectional pipe to the server.
From another class a separate thread is continuously trying to read the Named Pipe Client where the main thread tries to write to the Named Pipe Client when required.
In the ideal situation i want the Named Pipe Client's read method to return -1 or null when there in no incoming stream from the server and sleep for 100ms (which will allow the main thread to perform write operations if required) and then go for the next iteration of listening. Or at-least implementing a timeout for the read function is required.
I can not change the server/client communication to sockets since server is already implemented in C++ and can not be altered.
Please give me a hit to solve this...
I didn't know you could both read and write from / to a named pipe. I thought a pipe would be written to by one process and read from by a second process, so that reading and writing would be achieved by having two pipes, one from p1 -> p2 and one from p2 -> p1. where one process always writes to and the other process always reads from a given pipe.
I implemented 2 pipe approach first. Since my server was implemented in C++ which uses handles, the server identified it as 2 separate clients. So in that case i couldn't receive the response from the server for my named pipe client's write operation.
So i went for bidirectional pipe using "RandomAccessFile" (taking into account that pipes behave just as files) in java. Now i have got this issue that i can't timeout the read operation :(.