0

Actually the question in the title. I have a server-side Blazor app where the web client "talks" to the server via WebSocket. How can I make the mobile app (Android / IOS) establish a connection to the server via websocket? I don't need a code example, only the theory behind this idea, and the possible architectural design description.

I often hear that WebSockets are difficult to scale compared to the request-response APIs. But I need a live connection between all my clients and the server. So I am trying to mix and match.

And another thing I want to test - is building a Blazor Webassembly app with a WebSocket connection, instead of a REST API (I really don't like RESTs). The goal is to increase the performance of the app (REST's latency is awful), make it stateful and responsive to the server's events, and have the autonomy of the Webassembly's client. And my question regarding this part: how can I do that?

Elshad Shabanov
  • 483
  • 10
  • 17
  • Does this answer your question? [What's the difference between ASP.NET Core Hosted and Server-Side Blazor, really?](https://stackoverflow.com/questions/58093386/whats-the-difference-between-asp-net-core-hosted-and-server-side-blazor-really) – Yogi Apr 22 '22 at 12:36
  • `I have a server-side Blazor app where the web client "talks" to the server via WebSocket.` Please explain? In Server mode, Blazor code runs on the server, so either your code is server based or you are running JS code in the browser outside Blazor ????? – MrC aka Shaun Curtis Apr 22 '22 at 13:21
  • @MrCakaShaunCurtis I wasn't clear in my explanation. I mean that I have a regular server-side Blazor app, which normally uses a WebSocket connection (SignalR) to update the content in the browser. So I wonder, why I cannot use (at least out of the box) Websocket instead of REST with a client web app (Webassembly, JS etc.) – Elshad Shabanov Apr 22 '22 at 13:32
  • @Yogi, I read that thread, and also I have already built Asp.Net Core hosted WebAssembly app, using VS template. The problem is that in that template REST API connection is used for a server-client connection, but not SignalR (WebSocket). And I wonder how may I replace REST with SignalR, in a way so I could add also another client - mobile, desktop, etc. That's easy with REST to add another client, but I am not happy with REST, and I struggle to understand how that would work with WebSocket. – Elshad Shabanov Apr 22 '22 at 13:41
  • How about [Use ASP.NET Core SignalR with Blazor](https://learn.microsoft.com/en-us/aspnet/core/blazor/tutorials/signalr-blazor?view=aspnetcore-6.0&tabs=visual-studio&pivots=webassembly) ? – H H Apr 22 '22 at 13:50
  • And this one: [Can I incorporate both SignalR and a RESTful API?](https://stackoverflow.com/questions/12368800/can-i-incorporate-both-signalr-and-a-restful-api) Yet, what would be the advantage to using Signal-R? I don't see any, especially with the recommended 32kb size limit. – Yogi Apr 22 '22 at 14:24
  • 1
    @Yogi, one of the advantages of using Signal-R is the performance. As a simple test - if I try to fetch the same data from a database in SS Blazor and WASM Blazor, I can see a loading spinner for a second or more in the WASM. In SS Blazor I don't even see the loading spinner - it's that fast. And here REST API definitely is a bottleneck. Another advantage is that my client may respond to server events, such as alerts and notifications raised on another user's action – Elshad Shabanov Apr 22 '22 at 14:49
  • Researching this more, I understand that this would be useful in certain scenarios. Like WhatsApp uses websockets to connect millions of clients. I think this article answers your implementation question: [Which is best? WebSockets or SignalR](https://dotnetplaybook.com/which-is-best-websockets-or-signalr/) – Yogi Apr 22 '22 at 16:48
  • @ElshadShabanov - Thanks for answering my question. Lots of good advice here so I'll sign off :-) – MrC aka Shaun Curtis Apr 22 '22 at 18:51

0 Answers0