Mono System.Net.WebSockets implementation is buggy

This is my conclusion after trying for several days to implement Xamarin native WebSockets. I always try to not blame the framework but here this would have saved me quite some time. Everything was going wrong : packets were lost (especially if they were sent/received very quickly after the socket was opened, but it also happened later), and ClientWebSocket.ReceiveAsync() sometimes received the same packet twice (or even got stuck receiving the same packet again and again in an infinite loop). There were also quite a bunch of other issues about DNS name resolution and other stuff... It was only after trying the exact same code on a standard .NET platform that I realized everything was working fine.

Anyway, I tried to switch from native WebSockets to websocket-sharp in my Xamarin app and now everything works fine. I wouldn't even know what bugs to report as there isn't even a single part that is working well. But I hope this post will be useful if anyone get the same problem. Don't waste your time trying to make the native WebSockets work properly.

Posts

  • AlexWhiteAlexWhite GBMember ✭✭✭

    I have been using the using System.Net.Sockets within Xamarin for ages, I have it working perfectly on Synchronous sockets not on Async I had loads of trouble with Async sockets, I took my code from a project I wrote several years ago that worked flawlessly on windows and moved it over, only the Async stuff failed the rest worked perfectly.

    It is worth noting that in the mobile world we have to wait for the network stack to completely initialize which can take up to 10-12 seconds and we have to deal with issues like the network just disappearing whilst in mid process, this happens very frequently.

    atb

    alex

Sign In or Register to comment.