Reputation: 853
The server will be a web API in .Net and client is UWP app.There are some messages stored in the database along with the expiry time and deviceId.Each message should be broadcasted to the device on the expiration of time.How can we keep a persistent connection from web API to UWP and how can we broadcast the message to a particular device.Thanks in advance for all suggestion!
Upvotes: 0
Views: 616
Reputation: 3334
In the case you will you signalR (which will be a good solution) I suggest you to read:
https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server
Simple create a hub on server. Each client then should connect to this hub. After the connection is established you can send messages in both directions.
Here are some possibilities for sending messages from server to client:
Send message to all connected clients:
Clients.All.addNewMessageToPage(name, message);
To specific client:
Clients.Client(Context.ConnectionId).addContosoChatMessageToPage(name, message);
There are a lot other possibilities like groups.
Upvotes: 1
Reputation: 39072
The best solution for your scenario would be WebSockets
. These allow you to implement a lightweight two way connection between your app and the API and send data between them. Info on UWP implementation of WebSockets is here in documentation and for server side you can use ASP.NET SignalR for example.
Upvotes: 0