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

2023-09-07 01:53:58 作者:如梦

什么是正确的方式来建立在C#中通过网络命名管道?

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

目前我有两台机器,'客户'和'服务器'。

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".

每当我运行程序时,我得到一个System.UnauthorizedAccessException的,说:对路径的访问被拒绝。在code正常工作,当我运行我的本地机器并尝试连接到服务器和客户端。与客户端

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.

推荐答案

这是不可能用机器之间的命名管道。

It is not possible to used named pipes between machines.

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

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

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