Using the client and server examples found here: http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedmailslot14.html Compiling them with VS2008, running the server and then "client Myslot" I keep getting "WriteFail failed with error 53." Anyone have any ideas? Links to other Mailslot examples are also welcome, thanks.
Server:
// Server sample
#include <windows.h>
#include <stdio.h>
void main(void)
{
HANDLE Mailslot;
char buffer[256];
DWORD NumberOfBytesRead;
// Create the mailslot
if ((Mailslot = CreateMailslot("\\\\.\\Mailslot\\Myslot", 0, MAILSLOT_WAIT_FOREVER, NULL)) == INVALID_HANDLE_VALUE)
{
printf("Failed to create a mailslot %d\n", GetLastError());
return;
}
// Read data from the mailslot forever!
while(ReadFile(Mailslot, buffer, 256, &NumberOfBytesRead, NULL) != 0)
{
printf("%.*s\n", NumberOfBytesRead, buffer);
}
}
Client:
// Client sample
#include <windows.h>
#include <stdio.h>
void main(int argc, char *argv[])
{
HANDLE Mailslot;
DWORD BytesWritten;
CHAR ServerName[256];
// Accept a command line argument for the server to send a message to
if (argc < 2)
{
printf("Usage: client <server name>\n");
return;
}
sprintf(ServerName, "\\\\%s\\Mailslot\\Myslot", argv[1]);
if ((Mailslot = CreateFile(ServerName, GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with error %d\n", GetLastError());
return;
}
if (WriteFile(Mailslot, "This is a test", 14, &BytesWritten, NULL) == 0)
{
printf("WriteFile failed with error %d\n", GetLastError());
return;
}
printf("Wrote %d bytes\n", BytesWritten);
CloseHandle(Mailslot);
}