im trying to create a named pipe in one project, write to the pipe and have a second project read the data.
i have sample code which works, where the server creates the pipe and waits for the client to send IT data.
however im finding it hard to transmit from the server to client.
the pipe is being created successfully
and writing to the pipe is also successful
however when i try and get the data in the client it fails (INVALID_HANDLE_VALUE)
any help greatly appreciated.
(ps the working demo code can be found here
If somethings hard to do, its not worth doing - Homer Simpson
i have sample code which works, where the server creates the pipe and waits for the client to send IT data.
however im finding it hard to transmit from the server to client.
the pipe is being created successfully
Code:
hPipe = CreateNamedPipe ( lpszPipename,
PIPE_ACCESS_DUPLEX, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_NOWAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
BUFSIZE, // output buffer size
BUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL); // no security attribute
and writing to the pipe is also successful
Code:
HANDLE hFile;
char myName[32];
DWORD dwWrite;
BOOL flg;
hFile = CreateFile("\\\\.\\pipe\\BlackListPipe",GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);
for (q=0 ;q<32;q++)
{
myName[q]=wsb[dwHdrLen+3+q];
}
flg=WriteFile(hFile, myName, strlen(myName), &dwWrite, NULL);
if (flg==FALSE)
{
//Error
}
CloseHandle(hFile);
however when i try and get the data in the client it fails (INVALID_HANDLE_VALUE)
Code:
CHAR chRequest[BUFSIZE];
DWORD cbBytesRead;
HANDLE hFile;
BOOL flg;
DWORD dwWrite;
char szPipeUpdate[200];
hFile = CreateFile("\\\\.\\pipe\\BlackListPipe",GENERIC_READ,0, NULL,OPEN_EXISTING,0, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed for Named Pipe client\n" );
}
else
{
ReadFile (hFile, // handle to pipe
chRequest, // buffer to receive data
BUFSIZE, // size of buffer
&cbBytesRead, // number of bytes read
NULL); // not overlapped I/O
chRequest[cbBytesRead] = '\0';
printf("Data Received: %s\n",chRequest);
FlushFileBuffers(hFile);
DisconnectNamedPipe(hFile);
any help greatly appreciated.
(ps the working demo code can be found here
If somethings hard to do, its not worth doing - Homer Simpson