gpt4 book ai didi

c# - 使用命名管道时 Xamarin Forms 中的“方法或操作未实现”

转载 作者:太空宇宙 更新时间:2023-11-03 12:15:49 26 4
gpt4 key购买 nike

首先,大家好,这是我的第一篇文章。

进入案例:我正在尝试在两个应用程序之间发送消息 - 一个在计算机上,另一个在 Android 上通过命名管道并执行以下代码以“方法或操作未实现" 异常。

代码片段是一个 Button Clicked 事件 - 这个想法是打开一个管道,通过一个按钮文本发送(按钮文本是“Up”、“Down”、“Left”和“Right” ) 然后关闭管道。

我已经对此进行了测试,只要该项目是使用标准 System.IO.Pipes 的 WinForms 项目,它就可以正常工作。

    private void Button_Clicked(object sender, EventArgs e)
{
header.Text = "Pressed: " + (sender as Button).Text;
try
{
using (var pipeClient = new NamedPipeClientStream(SERVERNAME, "testpipe", PipeDirection.Out))
{
header.Text = "Connected with: " + SERVERNAME;
using (var stream = new StreamWriter(pipeClient))
{
pipeClient.Connect();

stream.Write((sender as Button).Text);
}
}
}
catch(Exception exc)
{
Debug.WriteLine(exc.StackTrace);
Debug.WriteLine(exc.Message);
}
}

创建异常的行是

using (var pipeClient = new NamedPipeClientStream(SERVERNAME, "testpipe", PipeDirection.Out))

我测试过服务器名(常量字符串)是 IP 地址、“本地主机”或计算机名称,没有任何变化。
我做错了什么还是 Xamarin 错误?

最佳答案

mono source for NamedPipeClientStream 中查找这仅适用于 win32。因此,您收到 NotImplementedException 是有道理的。

并非桌面上可用的所有 API 都在移动设备上受支持。

您可以使用 TCP 套接字或更高级别的东西作为 ASP.NET Core 服务器,而不是使用 NamedPipeClientStream客户。

关于c# - 使用命名管道时 Xamarin Forms 中的“方法或操作未实现”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49843369/

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