I'm trying to implement a named pipes server in .NET. The client will be C++. The nature of the data sent is not relevant to the question.
My first naive implementation looks something like:
using (NamedPipeServerStream stream =
new NamedPipeServerStream(PipeName,
PipeDirection.InOut,
numberOfListeners,
PipeTransmissionMode.Message))
{
while (true)
{
try
{
stream.WaitForConnection();
var request = ReadRequest(stream);
var reply = Process(request);
WriteReply(stream, reply);
stream.WaitForPipeDrain();
}
catch (Exception ex)
{
//TO DO: log
}
}
}
Am I approaching this right?
What would happen when two clients open a connection at the same time ?
Will they share the same stream and data will be intermingled ?
How can I avoid this?
Any ideas or resources on this will help. I'm pretty new to this topic.