여기에있는 클라이언트 및 서버 예제 사용 : http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedmailslot14.html 서버를 실행하고 "클라이언트 Myslot"을 실행하여 VS2008로 컴파일 "WriteFail이 (가) 오류 53으로 실패했습니다." 누구든지 아이디어가 있습니까? 다른 메일 슬롯 예제에 대한 링크도 환영합니다. 감사합니다.단순 메일 슬롯 프로그램이 작동하지 않습니까?
서버 :
// 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);
}
}
클라이언트 : 53 ERROR_BAD_NETPATH입니다
// 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);
}
어디에서 오류에 대한 설명을 찾았습니까? \\. \ mailslot \ myslot을 사용하면 지금 161이됩니다. – Shawn
따옴표/백 슬래시를 함께 사용하면 161 오류가 반환됩니다. – Shawn
아, 새 오류 코드. 161 = ERROR_BAD_PATHNAME. 네가 여기서 뭘하고 있는지 알 수가 없어. –