Xamarin Forms: How do I implement WebSockets?

11,987

WebSockets.PCL has a native implementation for each platform and it's well documented

https://github.com/NVentimiglia/WebSockets.Pcl

Share:
11,987
Shanakor
Author by

Shanakor

My name is Niklas Rammerstorfer and I am a passionate Mobile Application Developer. With a 5-year degree in Software Development my skillset is varied. However, my passion lies in the mobile sector. After completing various android projects, I now specialise in iOS Development and continous quality assurance. Codereviews, TDD, Clean Coding and Testable Code are some of the things that let my programmer heart leap.

Updated on June 23, 2022

Comments

  • Shanakor
    Shanakor almost 2 years

    We want to transfer data from a client to a server in realtime, so we have decided to go with WebSockets.

    Using Xamarin.Forms it was surprisingly difficult to find a suitable WebSocket library.

    The best match was "WebSocket4Net" because it is directly suggested on Xamarin's Homepage. However I was not able to install this library, because it only supports versions of .NET up to v4.0. (We are using v4.5)

    Whenever I try to change the target framework of my PCLs from v4.5 to v4.0 I get loads of weird errors stating "Windows.Input library could not be found", "ObservableCollection could not be found" etc.

    So we are currently using the library "WebSocket.Portable.Core", which although lacking some functionality worked out. However for some reason we can only receive one message. The event "MessageReceived" always is just called once.

    Has anyone heard about such a problem with WebSockets? Maybe it is just time to use another library, but I just can't find one?

    I also can't find any solution how to implement WebSockets natively for each platform.

  • Shanakor
    Shanakor over 7 years
    I have come across this library but for some reason I couldn't get it to work with the references.
  • Shanakor
    Shanakor over 7 years
    Anyway its is irrelevant now because we changed to native coding.
  • mmacneil007
    mmacneil007 about 7 years
    For future viewers this tutorial implements WebSockets.Pcl in XF with example code.