Push notifications for desktop apps?
Asked Answered
X

3

6

Push notifications for mobile apps allow for some cool possibilities in terms of user experience. Are similar services available for desktop apps, such as those written in Java or C#?

My goal is to let the program take actions based on notifications from a server. If push notifications aren't available, what are some workarounds I could do? Have the program schedule itself as a task (either a cron job, or scheduled task, or w/e), then check the server for updates? Keeping the program running in the background at all times wouldn't be an option, because updates would be too infrequent.

Xylophagous answered 24/3, 2011 at 23:47 Comment(0)
D
5

If you want push notifications, you don't have much choices other than having a process running at all times because the server would need a way to contact your application.

Using push notifications, you can either have a permanent connection with the server with sockets for example. When there is an update, the server would notify your application and you do whatever needs to be done.

However, if your updates are infrequent, a pull solution might be a better idea, because it wouldn't require a permanent connection.

Since your program doesn't need to be open all the time,

(Have the program schedule itself as a task (either a cron job, or scheduled task, or w/e), then check the server for updates? Keeping the program running in the background at all times wouldn't be an option, because updates would be too infrequent.)

you might just want to check with the server if an update is available at application startup (depending on your needs, hard to tell only with details from the question).

If you want, you might also add polling the server in a background thread wich checks for updates at a fixed interval (one that fits your needs).

Davena answered 25/3, 2011 at 4:12 Comment(6)
Thanks. In my use case, the program won't be opened regularly - it needs to be able to react to new data without the user running it.Xylophagous
To be able to react to new data without the user running it, you will need to have a service or some kind of process that runs in the background. A program can't just run and do something when it isn't running... A scheduled task could check if there is new data then launch your application. Without the context or any exemple of what you want to do, I can't help you more than that.Davena
can you share an example of using sockets in desktop app to keep a connection open?Clackmannan
@Clackmannan A lot has changed in software development since I answered this question. I would not recommend this option anymore. Sockets are kind of an expensive resource to keep open on your server for all clients. You would be better to periodically poll an url or better, use a cloud service like Azure AWS, which offer tech for push notifications.Davena
@Martin, polling would be a bad option as it would require hitting the server every X no. of seconds without getting any data. I doubt if Azure/AWS offer any push notification for desktop apps. Any ideas?Clackmannan
It depends on how frequent your data updates must happen, the required response time, etc. Azure offers push for desktop apps through windows universal apps. learn.microsoft.com/en-us/azure/app-service-mobile/…Davena
S
1

Since this question was originally asked, more options have become available. Now the Windows App SDK offers Push Notifications. This enables:

Application Wakeup - Push notifications can be used to wake up your application instead of it having to be constantly running which frees up user resources.

Real Time Sync - Push notifications can replace polling scenarios for your applications by sending push notifications to your clients and notifying them to sync with your web service

This also makes it unnecessary to have persistent connections. This is made possible by Windows Push Notification Services (WNS). Equivalent services exist for other platforms:

Southernmost answered 5/1, 2022 at 3:10 Comment(3)
Does it only work with UWP Apps or also with classic ".exe" Windows Application written in C++ / Java or Flutter?Hanaper
The first link in your post is dead, here is the correct one: learn.microsoft.com/en-us/windows/apps/windows-app-sdk/…Camber
When I made the post, Push Notifications via the Windows App SDK were in Beta and limited to a restricted set of windows applications, I'm not sure of the current status. However, the long term goal of Windows App SDK is to be one API for all windows applications - Windows 10, Windows 11, desktop, WinRT, WinUI, Win32, native C. learn.microsoft.com/en-us/windows/apps/windows-app-sdk/…Southernmost
P
0

You could just use a Push/Subscription service like Pusher (or implement it your self).

With Pusher you could just have an app, server, or anything that pushes an event and have the clients to be subscribed to Pusher for the specific event type, and then when the event arises it is notified to the clients.

Pigling answered 1/3, 2017 at 23:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.