I am sending message from service application to client application.
Named pipe is create in service application and client application is
receving data from service application.
Service Application Functions
bool InitServer()
{
...
m_hServer = ::CreateNamedPipe(m_strPipeName,
PIPE_ACCESS_OUTBOUND,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
sizeof maxSize,
sizeof maxSize,
NMPWAIT_USE_DEFAULT_WAIT,
&sa);
...
...
}
Client Application
bool InitClient()
{
DWORD dwError = 0;
while (true)
{
m_hClient = ::CreateFile( m_strPipeName,
GENERIC_READ,
0,
0,
OPEN_EXISTING,
0,
0);
if (m_hClient != INVALID_HANDLE_VALUE)
{
break;
}
if (GetLastError() != ERROR_PIPE_BUSY)
{
return false;
}
if (!WaitNamedPipe(m_strPipeName, 10000))
{
return false;
}
}
return true;
}
Above client code working when I am connecting first time.
After restart client application I am getting above mentioned error.
WaitNamedPipe - this gives [Error Number - 121 The semaphore timeout
period has expired]
I close the handle properly when client disconnect.
any clue to solve this?
-Manoj
It simply looks like you did not make your server wait on a client
connection through ConnectNamedPipe. Without a call to
ConnectNamedPipe in the server, I would be surprised that you can
connect your client even once, but it's a long time since I touched
pipes, so I could be wrong.
That said, if this is not "learning" code, is there a reason for use
of pipes? There are easier and more powerful ways to do IPC.
Goran.
Thank you Goran,
Sorry I didn't paste ConnectNamedPipe code, ConnectNamedPipe is there.
what are the other ways to do IPC?
-Manoj
I am speaking off the top of my head here... With pipes, operation
is:
ConnectNamedPipe on the server.
CreateFile on the client
communication
CloseHandle on the client
DisonnectNamedPipe on the server
I seem to remember that you get ERROR_PIPE_BUSY if server did not call
DisconnectNamedPipe for a previous connection, or if there really is
no pending ConnectNamedPipe.
Also, you might get better answers on some microsoft.public.win32
group.
Goran.