Xamarin Forms: How to implement WebSockets?

We want to transfer data from client to server in real time, so we decided to go with WebSockets.

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

The best match was "WebSocket4Net" because it is directly offered on the Xamarin homepage. However, I was unable to install this library because it only supports .NET versions up to version 4.0. (We use v4.5)

Whenever I try to change the target structure of my PCL from v4.5 to v4.0, I get a lot of weird errors in which "Windows.Input library was not found", "ObservableCollection could not be found", etc.

So, currently we use the library "WebSocket.Portable.Core", which, although it does not have any functionality, has been developed. However, for some reason we can only get one message. The MessageReceived event is always raised once.

Has anyone heard of such a problem with WebSockets? Maybe it's time to use another library, but I just can not find it?

I also cannot find a solution on how to implement WebSockets for each platform.

Thanks in advance

+7
websocket xamarin xamarin.android xamarin.forms
source share
2 answers

WebSockets.PCL has a built-in implementation for each platform and is well documented

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

+1
source share

You can see how we use WebSockets in the KinderChat application example:

https://github.com/xamarin/KinderChat

0
source share

All Articles