【发布时间】:2014-10-03 17:02:24
【问题描述】:
我想问您如何设置从远程客户端对我的命名管道服务器的可能访问。到目前为止,我认为 NamedPipes 只能用于同一台计算机上的进程间通信,但基于 http://msdn.microsoft.com/en-us/library/windows/desktop/aa365150%28v=vs.85%29.aspx 应该可以通过设置 PIPE_ACCEPT_REMOTE_CLIENTS / PIPE_REJECT_REMOTE_CLIENTS 来允许/不允许从远程计算机访问。我没有找到如何在 .NET 中设置此功能的简单方法。我想 PipeSecurity 可以以某种方式用于它,但我没有找到简单的方法。
我当前的解决方案允许所有用户访问我当前机器上的命名管道。有人可以改进我的解决方案以允许从另一台机器进行访问吗?
谢谢。
public NamedPipeServerStream CreateNamedPipeServer(string pipeName)
{
const int BufferSize = 65535;
var pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.ReadWrite, AccessControlType.Allow));
pipeSecurity.AddAccessRule(new PipeAccessRule("Administrators", PipeAccessRights.ReadWrite, AccessControlType.Allow));
return new NamedPipeServerStream(pipeName, PipeDirection.InOut, countOfServerInstancesToCreate, PipeTransmissionMode.Message, PipeOptions.Asynchronous,
BufferSize,
BufferSize);
}
【问题讨论】:
-
我想指出的是,允许从计算机 A 访问运行 NamedPipeServer 的计算机 B 并不简单。请参阅stackoverflow.com/questions/719353/… 了解更多信息
标签: .net namedpipeserverstream