I need help on my application I am making. It\'s a simple program that responds to command line parameters. If the application is invoked for the first time, it starts up as
You should handle communication with each client instance on a different server-side instance of the pipe, using a separate thread for each. So, when ConnectNamedPipe()
returns, immediately spawn a new listener thread to wait for the next client, before processing the message from the client which just connected.
Each client will then be talking via a freshly created instance of the pipe, and you won't see the ERROR_PIPE_NOT_CONNECTED
errors.
i.e. psuedo-code something like this:
Main Thread
{
CreateListenerThread();
WaitForQuitEvent();
}
ListenerThread
{
ConnectNamedPipe();
if (no error)
{
CreateListenerThread();
if( PeekNamedPipe() has a message )
{
ReadFile();
ProcessReceivedMessage(); // if -quit signal quit event
}
FileFlushBuffers();
DisconnectNamedPipe();
CloseHandle();
}
else
{
// handle/report error
}
}