简体   繁体   English

在xamarin表单pcl上安装System.Net.Sockets

[英]Install System.Net.Sockets on xamarin forms pcl

I have a problem. 我有个问题。 I need to use TcpClient on xamarin forms, but the "System.Net.Sockets" won't install. 我需要在xamarin表单上使用TcpClient,但是不会安装“ System.Net.Sockets”。 I can not use Nuget to install it. 我无法使用Nuget进行安装。

The error is.: 错误是:

Could not install package 'System.Net.Sockets 4.3.0'. 无法安装软件包“ System.Net.Sockets 4.3.0”。 You are trying to install this package into a project that targets '.NETPortable,Version=v4.6,Profile=Profile44', but the package does not contain any assembly references or content files that are compatible with that framework. 您正在尝试将此程序包安装到以'.NETPortable,Version = v4.6,Profile = Profile44'为目标的项目中,但是该程序包不包含任何与该框架兼容的程序集引用或内容文件。 For more information, contact the package author. 有关更多信息,请与软件包作者联系。

在此处输入图片说明

On iOS and Android projects this is able to install, but on this portable project it won't install. 在iOS和Android项目上可以安装,但在此便携式项目上则无法安装。

How could I solve this problem ? 我该如何解决这个问题?

Thanks 谢谢

Please see this thread on why you can't install socket class into PCL project, even if it's supported in Xamarin.iOS and Xamarin.Android. 请参阅此线程以了解为什么即使Xamarin.iOS和Xamarin.Android也支持将套接字类安装到PCL项目中。

Apart from using some of the PCL-ready socket nuget packages, you can also opt to install the System.Net.Socket to Android & iOS, and invoke them through DependencyServices. 除了使用某些PCL就绪的套接字nuget程序包之外,您还可以选择将System.Net.Socket安装到Android和iOS,并通过DependencyServices调用它们

You should try this plugin 你应该尝试这个插件

A tpc listner TPC列表器

var listenPort = 11000;
var listener = new TcpSocketListener();

// when we get connections, read byte-by-byte from the socket's read stream
listener.ConnectionReceived += async (sender, args) => 
{
    var client = args.SocketClient; 

    var bytesRead = -1;
    var buf = new byte[1];

    while (bytesRead != 0)
    {
        bytesRead = await args.SocketClient.ReadStream.ReadAsync(buf, 0, 1);
        if (bytesRead > 0)
            Debug.Write(buf[0]);
    }
};

// bind to the listen port across all interfaces
await listener.StartListeningAsync(listenPort);

Otherwise you can try to implement the Socket in Platform Specific code.. 否则,您可以尝试在特定于平台的代码中实现Socket。

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

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