Reputation: 3417
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
Upvotes: 0
Views: 1877
Reputation: 128
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.
Upvotes: 1
Reputation: 5768
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..
Upvotes: 0