2010-03-14 2 views
0

여기에있는 클라이언트 및 서버 예제 사용 : 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); 
} 

답변

1

오류 "네트워크 경로를 찾을 수 없습니다." 분명히 메일 슬롯에 잘못된 서버 이름을 사용하고 있습니다. 서버가 클라이언트와 동일한 시스템에서 실행되는 경우 \\.\mailslot\blah을 사용하십시오. 문자열에서 백 슬래시를 이스케이프 처리하는 것을 잊지 마십시오 : "\\\\.\\mailslot\\blah".

+0

어디에서 오류에 대한 설명을 찾았습니까? \\. \ mailslot \ myslot을 사용하면 지금 161이됩니다. – Shawn

+0

따옴표/백 슬래시를 함께 사용하면 161 오류가 반환됩니다. – Shawn

+0

아, 새 오류 코드. 161 = ERROR_BAD_PATHNAME. 네가 여기서 뭘하고 있는지 알 수가 없어. –

1

정확히 두 파일에 게시 된 코드를 VS2008로 컴파일하여 완벽하게 실행했습니다. 클라이언트 프로그램이 client.exe가 컴파일되면, 다음 명령을 입력 : 컴퓨터 이름이 도메인없이 PC의 이름입니다

client . 

또는

client <computername> 

. API GetComputerName을 호출하여 이름을 검색 할 수 있습니다.

관련 문제