【发布时间】:2012-02-10 01:47:09
【问题描述】:
我正在尝试制作一个需要通过网络进行通信的应用。我在这里关注命名管道的 MSDN 文档:http://msdn.microsoft.com/en-us/library/bb546085.aspx
我已经尝试过 MSDN 中的代码,但没有成功。
我看到了那个“。”必须用客户端的网络名称替换,我这样做了。我尝试了网络名称和服务器 PC 名称,但都无法连接到服务器(我的笔记本电脑)。
现在我不知道该怎么做 - 有什么建议吗? (下面的代码让我“找不到网络路径”)
using System;
using System.IO;
using System.IO.Pipes;
class PipeClient
{
static void Main(string[] args)
{
using (NamedPipeClientStream pipeClient =
new NamedPipeClientStream("xxx.xxx.x.x", "testpipe", PipeDirection.InOut))
{
// Connect to the pipe or wait until the pipe is available.
Console.Write("Attempting to connect to pipe...");
pipeClient.Connect();
Console.WriteLine("Connected to pipe.");
Console.WriteLine("There are currently {0} pipe server instances open.",
pipeClient.NumberOfServerInstances);
using (StreamReader sr = new StreamReader(pipeClient))
{
// Display the read text to the console
string temp;
while ((temp = sr.ReadLine()) != null)
{
Console.WriteLine("Received from server: {0}", temp);
}
}
}
Console.Write("Press Enter to continue...");
Console.ReadLine();
}
}
【问题讨论】:
-
服务器必须能够接受管道请求!
-
@DJ KRAZE - 代码与上面的 MSDN 文档链接相同,只是我更改了“。”如我所说。如何启用命名管道或如何知道服务器是否正在接受请求?
-
我希望我提供给你的链接能正常工作..对不起,我一分钟内无法回复我被跟踪回答另一个问题..如果你仍然有,请告诉我们这对你有什么影响问题..快乐编码..
标签: c#