그래서 명명 된 파이프를 통해 Unreal Engine 4 게임에 연결하는 C++ 응용 프로그램을 작성했습니다. 완벽하게 작동하는 시간은 95 %이지만 때로는 제대로 연결되지 않는 것 같습니다. 그것은 매우 무작위 적이기 때문에이 문제의 원인을 찾기가 어렵습니다. 서버가 내 애플리케이션에서 생성되고 클라이언트가 UE4 게임에서 생성됩니다. 그리고 때때로 UE4 게임은 연결하지 않고 디스플레이는 121 오류 : 나는 문제가 매우 무작위로 발생하고 나는 문제가 발생할 수있는 구체적인 이유를 찾을 수 없습니다 말했듯이명명 된 파이프가 작동하지 않는 경우가 있습니다.
//
// MessageId: ERROR_SEM_TIMEOUT
//
// MessageText:
//
// The semaphore timeout period has expired.
//
#define ERROR_SEM_TIMEOUT 121L
합니다. 파이프가 성공적으로 생성되었으므로 Windows powershell (get-childitem \. \ pipe)에서이를 볼 수 있습니다.
제가 사용하는 파이프 설정으로 할 일이 있을지도 모른다고 생각 했습니까?
이것은 파이프 서버 만들기위한 내 코드입니다 :
DWORD erPipeServer::CreatePipeServer() {
// create a SECURITY_ATTRIBUTES structure.
if (!CreatePipeSecurity(&pSa))
{
dwError = GetLastError();
//wprintf(L"CreatePipeSecurity failed w/err 0x%08lx\n", dwError);
Cleanup();
return dwError;
}
// Create the named pipe.
hNamedPipe = CreateNamedPipe(
pipename, // Pipe name.
PIPE_ACCESS_DUPLEX, // The pipe is duplex; both server and
// client processes can read from and
// write to the pipe
PIPE_TYPE_MESSAGE | // Message type pipe
PIPE_READMODE_MESSAGE | // Message-read mode
PIPE_NOWAIT, // Blocking mode is enabled
PIPE_UNLIMITED_INSTANCES, // Max. instances
BUFFER_SIZE, // Output buffer size in bytes
BUFFER_SIZE, // Input buffer size in bytes
NMPWAIT_WAIT_FOREVER, // Time-out interval
pSa // Security attributes
);
if (hNamedPipe == INVALID_HANDLE_VALUE)
{
dwError = GetLastError();
//wprintf(L"Unable to create named pipe w/err 0x%08lx\n", dwError);
Cleanup();
return dwError;
}
//wprintf(L"The named pipe (%s) is created.\n", pipename);
return dwError;
}
을 그리고 이것은 언리얼 엔진 4를 클라이언트를 만드는 내 코드입니다 :
// Try to open the named pipe identified by the pipe name.
while (true)
{
hPipe = CreateFile(
FULL_PIPE_NAME, // Pipe name
GENERIC_READ | GENERIC_WRITE, // Read and write access
0, // No sharing
NULL, // Default security attributes
OPEN_ALWAYS, // Opens existing pipe
0, // Default attributes
NULL // No template file
);
// If the pipe handle is opened successfully ...
if (hPipe != INVALID_HANDLE_VALUE)
{
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, FString::Printf(TEXT("The named pipe %d is connected."), FULL_PIPE_NAME));
break;
}
dwError = GetLastError();
// Exit if an error other than ERROR_PIPE_BUSY occurs.
if (ERROR_PIPE_BUSY != dwError)
{
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red, FString::Printf(TEXT("Unable to open named pipe ------ %d"),dwError));
goto Cleanup;
}
// All pipe instances are busy, so wait for 5 seconds.
if (!WaitNamedPipe(FULL_PIPE_NAME, 5000))
{
dwError = GetLastError();
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Red, FString::Printf(TEXT("Could not open pipe: 5 second wait timed out. %d"),dwError));
**THE 121 ERROR OCCURED HERE^^**
goto Cleanup;
}
}
가 파이프에 문제가 될 수 있을까 설정 또는 무엇인가? 나는 왜 항상 거의 항상 작동하는지 이해하지 못합니다. 그러나 때로는 분명한 이유 또는 이유가 없습니다. ...
사전에 도움을 주셔서 감사합니다!
그래서 오류 경우에 생각을 위해 노력하고 있습니다 파이프가 사용 중이며 5 초 후에'WaitNamedPipe' 시간 초과가 발생합니까? 또는'CreateFile'에서 오류 121입니까? –
예 클라이언트의 if 문에서 오류가 발생했습니다. if (! WaitNamedPipe (FULL_PIPE_NAME, 5000)) –
클라이언트를 다시 시작한 직후에 문제가 발생합니까? 어쩌면 핸들이 열린 상태로 유지되는 프로세스가 여전히 존재할 수도 있습니다. –