I will make a Xamarin application for Android that can access an ASP.NET MVC webserver with API's. The problem is when I'll send an API to the server, all the connected clients must receive an API with the changes that happens by client one. An example below:
In other words: The server must broadcast data by an API to all the clients when the they must update the UI with the information he get from the server.
The problem is on the client. How knows the clients when the server send an API to the client?
I had an idea to solve this problem with an infinitive loop on a thread (otherwise the app will block of course). The problem is now when there happens nothing on the server, there aren't send API's to the clients. But they are always listening to the server when there is nothing to do for a long time. Here is some pseudo code:
Are there better ideas then mine?
I'm wondering if there is an other secure solution for do the same things. I will something like open the connection and let the client wait if there is something to do without using an infinitive loop, like pseudo code below. If the client goes away, the connection to the server close.
Can you suggest me a good hint or pseudo code how I could do this?
P.S.: I make my applications with C#.