简体   繁体   中英

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. I can not use Nuget to install it.

The error is.:

Could not install package '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. 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.

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.

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.

You should try this plugin

A tpc listner

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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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