C# 3.5 - 跨网络连接命名管道 [英] C# 3.5 - Connecting named pipe across network

查看:23
本文介绍了C# 3.5 - 跨网络连接命名管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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

可以通过转到\server"在网络上访问server"机器.

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

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

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

这篇关于C# 3.5 - 跨网络连接命名管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆