如何通过网络使用命名管道? [英] How to use named pipes over network?
问题描述
我试图通过创建命名管道通过网络的连接。因为它在 MSDN <说我做的/ A>。我创建管道与功能的服务器端。
I'm trying to create a connection over network via named pipes. I'm doing it as it says in msdn. I create pipes server side with function.
CreateNamedPipe(
"\\\\.\\pipe\\myNamedPipe",
DUPLEX | FILE_FLAG_OVERLAPPED,
0,
255,
BUFFER_SIZE,
BUFFER_SIZE,
0,
IntPtr.Zero);
和尝试通过的CreateFile()函数
and trying to connect via CreateFile() function
CreateFile(
"\\\\10.0.0.29\\pipe\\myNamedPipe",
GENERIC_READ | GENERIC_WRITE,
0,
IntPtr.Zero,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
IntPtr.Zero);
10.0.0.29是服务器的机器的IP。如果我想的服务器机管道名\\.\pipe\myNamedPipe或\\10.0.0.29\pipe\myNamedPipe上运行的客户端程序(10.0.0.29是服务器IP)或\\localhost\pipe\myNamedPipe它工作正常。
10.0.0.29 is server machines ip. If I'm trying to run client side program on server machine with pipe name "\\.\pipe\myNamedPipe" or "\\10.0.0.29\pipe\myNamedPipe" (10.0.0.29 is servers ip) or "\\localhost\pipe\myNamedPipe" it works fine.
因此,如何通过网络使用命名管道?
So how to use named pipes over network?
推荐答案
3.5版本开始,命名管道本身在.NET Framework的支持,你不必使用繁琐的互操作的p / Invoke的代码。在这里看到这样的介绍文章: .NET 3.5中添加支持命名管道一>的样本。
Starting with version 3.5, named pipes are supported natively in the .NET Framework, you don't have to use tedious interop p/invoke code. See this introduction article here: .NET 3.5 Adds Named Pipes Support for a sample.
使用这个构造函数重载,的 NamedPipeClientStream构造函数(字符串,字符串),则可以通过服务器名称参数。
Using this constructor overload, NamedPipeClientStream Constructor (String, String), you can pass a server name argument.
这篇关于如何通过网络使用命名管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!