views:

102

answers:

4

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.

A: 

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.

jldupont
+2  A: 

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.

Fire Lancer
A: 

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

http://website.com/checkupdates.php?v=&lt;current_version&gt;

Your program fills in current_version.

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

Galen
+1  A: 

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 ...
}
ChronoFish
Thanks, that's the sort of thing I'm looking for (I think), but where does "Update required" get 'printed'? How would my application read it?
issy
Your application would read it as the response from that web page you are requesting. Your application then just takes that response and displays it to the user.
macca1
Rigth - the output (print) of the PHP side would become a returned string of the function that calls the web page. I've updated my answer to reflect this
ChronoFish