1

I'm writing an app which communicates with an embedded linux server via tcp sockets. And I'm looking for a way to write common client code targeting iOS and Android devices using Xamarin C#.

I wanted to know if the TcpClient class (System.Net.Sockets) can be used in a pcl targeting iOS and Android. If not, what other options do I have?

WeSt
  • 2,628
  • 5
  • 22
  • 37
Zaxter
  • 2,939
  • 3
  • 31
  • 48
  • 1
    related http://stackoverflow.com/questions/14283746/net-portable-class-library-and-udp-support – kenny Jan 02 '15 at 17:32
  • Thanks @kenny. I looked at that. Looks like Socket class wasn't supported in pcl, atleast until Jan 2013. I found [this](http://forums.xamarin.com/discussion/2549/tcp-ip-example-for-ios-needed) on xamarin's forum, which shows that the socket class can be used on both ios and android, but I haven't tried it yet. – Zaxter Jan 02 '15 at 17:43

1 Answers1

5

I've just released the first version of a library that wraps over the .NET and WinRT socket implementations, allowing you to write socket code in your PCLs that target Xamarin iOS/Android, Windows Store, Phone and Desktop. Depending on the level of configurability you need, the TcpSocketClient class may do the trick.

It relies on the 'Bait and Switch' PCL pattern, so you'll need to install the nuget package in both your PCL project and the native platform projects.

rdavisau
  • 895
  • 6
  • 12