我正試圖製作一個需要通過網絡進行通信的應用程序。我在這裏命名管道的MSDN文檔如下:http://msdn.microsoft.com/en-us/library/bb546085.aspx通過網絡命名管道的C#
我試過從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();
}
}
服務器必須能夠接受管道請求! – vulkanino 2012-02-09 16:55:34
@DJ KRAZE - 代碼與上面的MSDN文檔鏈接相同,只是我更改了「。」。如我所說。如何啓用命名管道,或者如何知道服務器是否接受請求? – Michael 2012-02-09 16:58:19
我希望我提供給你的鏈接能夠解決。讓我回答一分鐘以迴應我跟蹤回答了另一個問題。讓我們知道如何解決這個問題,如果你仍然有問題..快樂編碼.. – MethodMan 2012-02-09 17:02:13