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

发布于 2024-07-08 05:03:44 字数 751 浏览 8 评论 0 原文

在 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,显示“访问路径被拒绝”。 当我在本地计算机上运行服务器和客户端并尝试连接到“.”时,代码工作正常。 与客户。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惯饮孤独 2024-07-15 05:03:44

您需要在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.

囍笑 2024-07-15 05:03:44

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

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

黑白记忆 2024-07-15 05:03:44

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

“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文