我有一个我正在尝试实现的简单设计。
单个基于 C++ 的服务器应用程序创建一个只写的命名管道。多个客户端(C++ 或 C#)以只读方式连接并侦听状态消息。
我有这个适用于本地进程,但我无法将不同主机上的客户端连接到服务器。
服务器在 XP SP2(可能是 SP3)上运行。客户端在 Win7 上运行。
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
SID_IDENTIFIER_AUTHORITY siaWorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY;
PSID psidWorldSid = (PSID) LocalAlloc (LPTR, GetSidLengthRequired(1));
InitializeSid(psidWorldSid, &siaWorldSidAuthority, 1);
*(GetSidSubAuthority(psidWorldSid, 0)) = SECURITY_WORLD_RID;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorGroup(&sd, psidWorldSid, TRUE);
ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
HANDLE hPipe = CreateNamedPipe(
lpszPipename, // name
PIPE_ACCESS_OUTBOUND, // write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
BUFSIZE, // output buffer size
BUFSIZE, // input buffer size
PIPE_TIMEOUT, // client time-out
NULL /*&sa*/); // no security attribute
在最后一个参数中用 &sa 替换 NULL 无效。C# 客户端代码如下所示。
SafeFileHandle pipeHandle =
CreateFile(
pipeName,
GENERIC_READ,
0,
IntPtr.Zero,
OPEN_EXISTING,
0,
IntPtr.Zero);
我在这里错过了什么愚蠢的显而易见的事情?