Guide to using WebSockets in Xamarin apps

prashantvcprashantvc USXamarin Team Xamurai
edited October 2017 in Xamarin Blog

Read the blog post here

Please discuss the post below


  • BjornBBjornB USMember ✭✭✭

    I really think you should mention SignalR in this post. Before someone crates a giant framework using Websockets at this level :)

  • prashantvcprashantvc USXamarin Team Xamurai

    @BjonB Good point, I believe we already have SignalR post on the blog. I will have that linked in the blog :)

  • lawwyyylawwyyy USMember

    Awesome blog !!

  • GuyAssafGuyAssaf USMember

    What about portable (PLC) xamarin forms projects.
    I cannot install the WebSockets nuget on a portable project

  • As GuyAssaf alread mentioned, it is not possible to install the nuget package. The only way i was able to install it was after switching my Xamarin.Forms project to .netstandard1.5 and change my Xamarin.Forms version in the project.json file.

    "Xamarin.Forms": ""

    But then i've encountered other problems... maybe thats why i'm using a mac and the ability to create .netstandard xamarin.forms projects for mac are still in development as you can find here

  • batmacibatmaci DEMember ✭✭✭✭

    is that useful also updating sqlitedata from the cloud whenever data is changed? So I dont want mobile app to always ask for changes from the server but when I update data in the server, i want to inform client that there is new data. Is this or signalR is the best solution for it? beside that It keeps listening, does it use battery of the phone?

  • junkomaticjunkomatic Member ✭✭

    i found (using xamarin.forms | standard 2.0) that the await.TaskFactory.StartNew call is causing my program to hang during .RecieveAsync.

    I put the while loop inside its own Recieve() task and then called it with await Task.WhenAll(Receive()) and that seems to work much better.

  • junkomaticjunkomatic Member ✭✭
    edited January 21


  • junkomaticjunkomatic Member ✭✭
    edited January 21

    @BjornB said:
    I really think you should mention SignalR in this post. Before someone crates a giant framework using Websockets at this level :)

    Also its worth mentioning that SignalR does NOT support websocket transport for net standard, long polling only. SignalR has not been updated in a few years, and as far as I can tell, they have no further plans.

  • StephenHauckStephenHauck USMember ✭✭✭

    Nice article, I did have a question though....
    Does the client automatically retry when it loses it's connection or do I have to have code watch for that in my app?
    If I need code to monitor connectivity what's the best way in your experience to do that in a Xamarin.Forms app?

  • GregCadmesGregCadmes USUniversity ✭✭

    @StephenHauck We had a similar need for our websocket code.
    We ended up adding a timer that continuously got reset each time a packet was received. When the connection is lost, no data received, at which point, our websocket would raise an event to any subscribers. (due to the timer expiring)

  • GregCadmesGregCadmes USUniversity ✭✭
    edited March 28

    Great blog, thank you!

  • StephenHauckStephenHauck USMember ✭✭✭

    Can I ask what you used... system.timer or the xamarin.forms device timer implementation?
    Where did you put the code, in the AppDelegate ?


Sign In or Register to comment.