C# 3.5 - 跨网络连接命名管道

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/244367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:36:50  来源:igfitidea点击:

C# 3.5 - Connecting named pipe across network

c#.net-3.5networkingnamed-pipes

提问by Anton

What is the correct way to setup a named pipe in C# across a network?

通过网络在 C# 中设置命名管道的正确方法是什么?

Currently I have two machines, 'client' and 'server'.

目前我有两台机器,“客户端”和“服务器”。

Server sets up its pipe in the following manner:

服务器以下列方式设置它的管道:

NamedPipeServerStream pipeServer = new NamedPipeServerStream(
    "pipe",
    PipeDirection.InOut,
    10,
    PipeTransmissionMode.Byte,
    PipeOptions.None)
pipeServer.WaitForConnection();
//... Read some data from the pipe

The client sets up its connection in the following manner:

客户端以下列方式建立其连接:

NamedPipeClientStream pipeClient = new NamedPipeClientStream(
    "server",
    "pipe",
    PipeDirection.InOut);
pipeClient.Connect(); //This line throws an exception
//... Write some data to the pipe

The 'server' machine can be accessed on the network by going to "\\server".

可以通过转到“\\server”在网络上访问“server”机器。

Whenever I run the program, I get a System.UnauthorizedAccessException that says "Access to the path is denied." The code works fine when I run the server and client on my local machine and attempt to connect to "." with the client.

每当我运行该程序时,我都会收到一个 System.UnauthorizedAccessException,显示“对路径的访问被拒绝”。当我在本地机器上运行服务器和客户端并尝试连接到“.”时,代码工作正常。与客户。

采纳答案by Shiraz Bhaiji

It is not possible to used named pipes between machines.

机器之间不能使用命名管道。

"The WCF-NetNamedPipe adapter provides cross-process communication on the same computer"

“WCF-NetNamedPipe 适配器在同一台计算机上提供跨进程通信”

http://msdn.microsoft.com/en-us/library/bb226493.aspx

http://msdn.microsoft.com/en-us/library/bb226493.aspx

回答by Joel Coehoorn

Look in the System.Runtime.Remoting namespace. IIRC, named pipes are one option for the protocol used by remoting channels.

查看 System.Runtime.Remoting 命名空间。IIRC,命名管道是远程通道使用的协议的一种选择。

回答by John Lemp

You need to set permissions on the NamedPipeServerStream so that the client will have permissions to access the pipe.

您需要在 NamedPipeServerStream 上设置权限,以便客户端有权访问管道。

I would look at the SetAccessControl method of your NamedPipeServerStream.

我会查看您的 NamedPipeServerStream 的 SetAccessControl 方法。