Reputation: 7584
I'm writing a desktop application that needs to respond to a change on my server that could happen at any time, and I want the application to be always running whenever the computer is logged in. Is there a way that is considered most standard or ways that should be avoided? Several solutions I have considered are:
If the server just returns an error or a short short message whenever theres no data, would it be bad to use the first option? Would that affect other network activity on the network?
Thanks in advance!!
Upvotes: 3
Views: 1567
Reputation: 3894
As Mark Setchell said, avoid unnecessary polling.
WebSocket is not just for browsers. Desktop applications can also use WebSocket. If your application establishes a connection to the server, facilitated by WebSocket, then it can receive data or events asynchronously. No polling.
Now your desktop application can sit there, and whenever it receives an event or data from the server, it can take whatever action you desire.
But how would I notify the desktop client without starting a server on the client and opening the client's firewall for incoming connections?
Using WebSocket in this way also prevents your client opening up an inbound port in their firewall, as they are the one that initiated the (outbound) connection.
Upvotes: 7
Reputation: 208077
If the server knows when there are updates available it would be best placed to notify your desktop application surely? That would avoid unnecessary polling.
In any case, I would probably have a separate thread that exclusively communicates with the server and (after maybe locking a semaphore) updates some global variables that the main thread is using whenever updates are available.
Upvotes: 0