2016-12-29 1 views
1

두 Windows PC간에 명명 된 파이프를 통해 메시지를 보내려고합니다. CreateNamedPipe을 로컬로 호출하면 모든 것이 잘 동작합니다. 호스트 이름을 "\\\\.\\pipe\\testpipename"에서 "\\\\myHostname\\pipe\\testpipename"으로 변경하면 ERROR_INVALID_NAME(123)getLastError()에서 발생합니다.C++ 명명 된 파이프를 통한 네트워크 유효하지 않은 이름 오류

BOOL fConnected = FALSE; 
    DWORD dwThreadId = 0; 
    HANDLE hPipe = INVALID_HANDLE_VALUE, hThread = NULL; 
    LPTSTR pipeName = /*nullptr*/ TEXT("\\\\myHostname\\pipe\\testpipename"); 

    SECURITY_ATTRIBUTES sa = { 0 }; 
    SECURITY_DESCRIPTOR sd = { 0 }; 

    InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION); 

    SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE); 

    sa.bInheritHandle = false; 
    sa.lpSecurityDescriptor = &sd; 
    sa.nLength = sizeof(sa); 

    hPipe = CreateNamedPipe(
    pipeName,     // pipe name 
    PIPE_ACCESS_DUPLEX,  // read/write access 
    PIPE_TYPE_MESSAGE |  // message type pipe 
    PIPE_READMODE_MESSAGE | // message-read mode 
    PIPE_WAIT,    // blocking mode 
    PIPE_UNLIMITED_INSTANCES, // max. instances 
    255,      // output buffer size 
    255,      // input buffer size 
    0,      // client time-out 
    &sa);      // default security attribute 

    if (hPipe == INVALID_HANDLE_VALUE) 
    { 
     cout << GetLastError(); 
     return -2; 
    } 

    cout << "Waiting for client to connect!" << endl; 

    //waiting for client to connect 
    fConnected = ConnectNamedPipe(hPipe, NULL) ? 
     TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); 

    cout << "Client connected! YEAH" << endl; 

내 생각은 pipename이 무효라고하지만 난 그 이유를 알고하지는 :

이 내 코드입니다. 어떤 아이디어?

+0

호스트 이름 대신 IP 주소를 사용해 보셨습니까? – fsp

+0

@ user3549596 그래, 같은 오류가 발생합니다. – Strizzi

+0

바보 같이 들릴 수도 있지만 파이프 이름이 정확하며 서버에서 허용되는 포트 445 인바운드입니까? – fsp

답변

0

문제가 해결되었습니다. 서버 및 클라이언트에 대한 Pipenames은 다음과 같습니다

서버 : "\\\\.\\pipe\\testpipe"
클라이언트 : 클라이언트에서 "\\\\serverHostName\\pipe\\testpipe"

일부 사소한 변화도 만들어졌다. 전체 코드는 my Github repo에서 찾을 수 있습니다.

관련 문제