windows Win32 命名管道和远程客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/719353/
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
Win32 named pipes and remote clients
提问by Brian R. Bondy
Can I access a named pipe on computer A from computer B given computer A's IP address? If so, what do I need to do to make this happen?
给定计算机 A 的 IP 地址,我可以从计算机 B 访问计算机 A 上的命名管道吗?如果是这样,我需要做什么才能实现这一目标?
回答by Brian R. Bondy
Yes you can communicate across the network via named pipes. You specify the pipe name like a UNC path:
是的,您可以通过命名管道在网络上进行通信。您可以像 UNC 路径一样指定管道名称:
\\computername\pipe\pipename
\\computername\pipe\pipename
or via IP
或通过IP
\\192.168.0.100\pipe\pipename
\\192.168.0.100\pipe\pipename
You can do this for any LAN machine, or for any remote machine connected to your LAN via VPN.
您可以对任何 LAN 机器或通过 VPN 连接到 LAN 的任何远程机器执行此操作。
You use all of the same pipe Win32 API functions such as CreateFile. To create the pipe you use CreateNamedPipe.
您使用所有相同的管道 Win32 API 函数,例如CreateFile。要创建管道,请使用CreateNamedPipe。
Before you can use a remote pipe, you must have a valid connection to the remote computer. To do this you would use an API like WNetUseConnection. Or if your computer is on the same domain, or has the same u/p you don't need to use WNetUseConnection at all.
在您可以使用远程管道之前,您必须具有到远程计算机的有效连接。为此,您将使用像WNetUseConnection这样的 API 。或者,如果您的计算机在同一个域中,或者具有相同的 u/p,则根本不需要使用 WNetUseConnection。
If you are running your program as a service, you cannot access LAN resources with the local system account. The service would have to be configured with another account.
如果您将程序作为服务运行,则无法使用本地系统帐户访问 LAN 资源。该服务必须使用另一个帐户进行配置。
回答by aJ.
Named pipes can be used to provide IPC between processes on different computers across a network. Refer MSDN.
命名管道可用于在网络上不同计算机上的进程之间提供 IPC。参考MSDN。
If you are having Windows XP SP2, Windows Server 2003 SP1 and later versions, then don't forget to enable the named pipe filtering. Refer here.
如果您使用的是 Windows XP SP2、Windows Server 2003 SP1 和更高版本,请不要忘记启用命名管道过滤。请参阅此处。
回答by aJ.
Be aware, pipes under Windows are bloody awful. There's a lot of crucial detail you need to get exactly right, or they fail strangely and the documentation isn't up to scratch.
请注意,Windows 下的管道非常糟糕。有很多关键细节需要完全正确,否则它们会奇怪地失败并且文档不符合标准。
If you can, use sockets.
如果可以,请使用套接字。