gpt4 book ai didi

网络上的 C# 命名管道

转载 作者:行者123 更新时间:2023-11-30 22:31:28 25 4
gpt4 key购买 nike

我正在尝试制作一个需要通过网络进行通信的应用程序。我在这里关注命名管道的 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();
}
}

最佳答案

当您指定计算机名称时,即使是您自己的计算机名称,它也会使用标准网络协议(protocol)/堆栈/等。

您可能需要打开防火墙端口。 TCP 445。此外,默认情况下,Windows 允许所有传出通信。您应该只需要添加入站端口异常(exception)。您的配置当然可能会有所不同。 .NET 3.5 (C#) Named pipes over network

关于网络上的 C# 命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9215100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com