简体   繁体   English

实现rda.SocketsForPCL Xamarin形成PCL

[英]implementing rda.SocketsForPCL Xamarin forms PCL

I need to create a tcp connection to the wireless router connected to the device, and then pass a buffer of data. 我需要创建一个连接到设备的无线路由器的TCP连接,然后传递数据缓冲区。 That said, I installed the plugin from NuGet, Socket.Plugin , but this generates me error: 也就是说,我从NuGet, Socket.Plugin安装了插件,但这会产生我的错误:

The empty PCL implementation for Sockets was loaded. 已加载Sockets的空PCL实现。 Ensure you have added the Sockets nuget package to each of your platform projects. 确保已将Sockets nuget包添加到每个平台项目中。

implementation in the xamarin forms pcl project: 在xamarin表单中实现pcl项目: 在此输入图像描述

call method: 通话方式:

  var address = "192.168.222.1";
  var port = 5555;
  var r = new Random();

    try
    {
       var client = new Sockets.Plugin.TcpSocketClient();
       await client.ConnectAsync(address, port);
    }
    catch(Exception ex)
    {
        throw ex;
    }

在此输入图像描述

When i launch the app on device, i have this error: 当我在设备上启动应用程序时,我有这个错误:

The empty PCL implementation for Sockets was loaded. 已加载Sockets的空PCL实现。 Ensure you have added the Sockets nuget package to each of your platform projects. 确保已将Sockets nuget包添加到每个平台项目中。

Why do I get that error? 为什么我会收到这个错误? everything is connected and everything is connected. 一切都是连通的,一切都是连通的。 How can I fix? 我该怎么办? I forgot something? 我忘记了什么?

I don't know what conclusion the OP came to, but I was having this same issue. 我不知道OP的结论是什么,但我遇到了同样的问题。 I was using the NuGet package "rda.SocketsForPCL" in a portable project. 我在便携式项目中使用NuGet包“rda.SocketsForPCL”。

I was referencing the portable project in a Windows application project. 我在Windows应用程序项目中引用了可移植项目。 When trying to create a TcpSocketClient in the portable project, it would throw an exception. 当尝试在可移植项目中创建TcpSocketClient时,它会抛出异常。 Turns out that the NuGet package not being referenced in the Windows application was causing this exception. 事实证明,Windows应用程序中未引用的NuGet包导致此异常。

So, adding the NuGet reference to the Windows application project solved the issue. 因此,将NuGet引用添加到Windows应用程序项目解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM