C# 3.5 - 通过网络连接命名管道
在 C# 中跨网络设置命名管道的正确方法是什么?
目前我有两台机器,“客户端”和“服务器”。
服务器按以下方式设置其管道:
NamedPipeServerStream pipeServer = new NamedPipeServerStream(
"pipe",
PipeDirection.InOut,
10,
PipeTransmissionMode.Byte,
PipeOptions.None)
pipeServer.WaitForConnection();
//... Read some data from the pipe
客户端按以下方式设置其连接:
NamedPipeClientStream pipeClient = new NamedPipeClientStream(
"server",
"pipe",
PipeDirection.InOut);
pipeClient.Connect(); //This line throws an exception
//... Write some data to the pipe
可以通过转至“\\server”在网络上访问“服务器”计算机。
每当我运行该程序时,都会收到 System.UnauthorizedAccessException,显示“访问路径被拒绝”。 当我在本地计算机上运行服务器和客户端并尝试连接到“.”时,代码工作正常。 与客户。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在NamedPipeServerStream上设置权限,以便客户端有权访问管道。
我会查看您的 NamedPipeServerStream 的 SetAccessControl 方法。
You need to set permissions on the NamedPipeServerStream so that the client will have permissions to access the pipe.
I would look at the SetAccessControl method of your NamedPipeServerStream.
查看 System.Runtime.Remoting 命名空间。 IIRC,命名管道是远程通道使用的协议的一种选择。
Look in the System.Runtime.Remoting namespace. IIRC, named pipes are one option for the protocol used by remoting channels.
不可能在机器之间使用命名管道。
“WCF-NetNamedPipe 适配器在同一台计算机上提供跨进程通信”
http://msdn.microsoft.com/en-us/library/bb226493.aspx
It is not possible to used named pipes between machines.
"The WCF-NetNamedPipe adapter provides cross-process communication on the same computer"
http://msdn.microsoft.com/en-us/library/bb226493.aspx