English 中文(简体)
How does a desktop application get information back from a website?
原标题:

I m a desktop application developer. I m creating a basic website from which to sell an application I ve written, and learning some web tech along the way, but haven t learnt that much yet (my chosen CMS - Textpattern - has saved me learning much PHP so far).

I want my desktop application to call my website and say "I m version x.x.x.x", and I need it to get back a response - at a minimum "there is/isn t an update", preferably also "it s an xKB download and has these features..." - so that I can display the information to users and ask them if they want to download it.

I can send a request from my app (once I get my head round Qt s QtNetwork module). My question is, what do I need to learn in order to be able to create and send the appropriate response from the website.

I m fine with learning any necessary new tech/languages, I just want to be sure I m learning the right stuff and not going down the wrong road. Any help is much appreciated.

最佳回答

Simplest way to use a webservice is via REST:

Here s a very quick and dirty PHP Script saved as "versioncheck.php" in your server document_root - to simply get the point accross:

<?
define ("CURRENT_VERSION", "5");

$version = $_REQUEST[ version ];

if ($version < CURRENT_VERSION) print "Update required";
else print "YOU RE ALL GOOD";
?>

Your app would call http://wwww.yoursever.com/versioncheck.php?version=2

So let s assume your desktop app has a function called "getHTTP" which can retrieve an HTTP page. And the variable "currentVersion" is your desktop apps current version number.
So your code would be something like this:

//NOTE: I don t know the syntax of your desktop app s language, so just treat this as highlevel pseudo code.

/** all sorts of other goodness **/
//CheckVersion
upgrade = getHTTP("http://wwww.yoursever.com/versioncheck.php?version="+currentVersion); 
if (upgrade == "Update Required") then doUpdate(); // doUPdate is some function you ve defined to act as a handler for when an update needs to occur
else
{
... continue on with app ...
}
问题回答

The easiest way is to use the HTTP protocol. Pass the app version as a get argument (ie "www.yoursite.com/auto/update.php?version=1.0.2") and the echo something back instead of HTML, eg "up to date" or "new version:1.1.0".

Theres a number of libraries to help you with the desktop side for whatever language and platform your using (not sure if QT includes the HTTP stuff, although I suppose you could just do all the HTTP header stuff yourself).

EDIT: For what the php side does, you could have something simple like

(Hopefully this logic is right, I just came up with it quickly :) )

<?php
    //change this whenever you bring out a new version
    $current_version = array(1, 1, 0);

    $version = $_GET[ version ];

    //split the version string into the 3 numeric parts
    $version = split( . , $version);

    //compare $version and $current_version
    if(    $version[0] < $current_version[0]
        || $version[1] < $current_version[1]
        || $version[2] < $current_version[2])
    {
        echo "update_needed, $current_version[0].$current_version[1].$current_version[2]";
    }
    else echo "up_to_date";
?>

Obv if you use a different version string to "x.x.x" then you need to change the code as needed. If you decide to only a single version number, you can replace the array stuff with a single if($version < $current_version).

IF its possible to get a version newer than the current version (eg during testing, beta, etc) then that code may incorrectly report an update (eg if the user had a 2.0.0 test version, and the "offical" version was 1.3.0 then it would say an update was needed because 0 < 3) so you need to change it to handle that, however you hopefully get the idea.

HTTP with XML/JSON is a good starting point.

Have your server side respond to an XML/JSON query sent over HTTP.

In your case, it could just well be an XML document just being served by your web server.

It can be as simple as having your app make a request to

http://website.com/checkupdates.php?v=<current_version>

Your program fills in current_version.

The php script checks to see if there s a new version and responds with information accordingly.





相关问题
Capture desktop without my window

I want to create a recording of desktop content, but without a certain window. The role of this window is to provide a text that will be read, while recording desktop changes. Any suggestions?

Logout from an desktop application to change user in C#.net

I have designed an desktop application using C#.net that has many users. Each USer has specific rights. The User logs into the system when the application first starts and the UserID number is stored ...

Programmatically take ScreenShot of Desktop in Ruby?

I asked this question about taking a picture of a webpage programmatically, and I ve downloaded and got webkit2png working (taking pictures of HTML pages like blogs and whatnot). So cool, thanks for ...

热门标签