首先,大家好,因为这是我的第一篇文章。
说明案例:我正在尝试在两个应用程序之间发送消息 - 一个在计算机上,另一个在Android上通过命名管道发送消息并执行以下代码最终以“方法或操作未实现“例外。
代码片段是 Button Clicked 事件 - 想法是打开管道,通过按钮文本发送(按钮文本是“向上”,“向下”,“向左”和“向右” )然后关闭管道。
我已经对此进行了测试,只要该项目是使用标准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))
我测试过servername(const string)是一个IP地址,“localhost”或计算机名称,没有任何变化。
我做错了什么或这是一个Xamarin错误?
答案 0 :(得分:1)
查看mono source for NamedPipeClientStream
这只适用于win32。因此,获得NotImplementedException
并非移动设备支持桌面上的所有API。
您可以使用TCP套接字或更高级别的内容作为ASP.NET Core服务器,而不是使用NamedPipeClientStream
,而是将您需要的内容暴露为RESTful API或类似内容,并使用HttpClient或任何其他REST客户端来使用它。 / p>