Simple Idea of software networking detection version

Source: Internet
Author: User
Tags response code dedicated server

Currently, software updates usually have a dedicated server or a website module that writes a certain amount of response code, but the small software we make is not so large, or we personally
What if there is no dedicated server or website? I 've been thinking about this for a long time, and finally I got an inspiration. The software networking check version is nothing more than connecting to the specified website, with specific content
For comparison, this is the simplest idea, so we can think of it as long as I have a platform that can provide a software version to compare with it. So I thought of using blogs, or even
QQ space, but after testing, I found that QQ space is quite troublesome. Many things are implemented using scripts, so it is not convenient to directly obtain what we want, so we use blogs.

In this way, we can create a blog post specifically, which is my case: Software Update
It is written in a certain format (so that we can use regular expressions to match ):

Cssoftversion = no

1.1 = no

1.2 = no

1.3 = OK


The first line is meaningless, but it was written during the test. It is the same as deletion and does not affect the use.
1.1 = no indicates that version 1.1 is not the latest version, and the software gives a friendly prompt. As for how to prompt and update the version, you can decide on your own.
1.3 = OK indicates the latest version.

We can use network programming and regular expressions to obtain the source code of blog articles. Match and compare them:
First:
Public static string softVersion = "1.1 ";
Defines a static global variable to record the current software version.

Next, write several methods:
Static int connectionDescription = 0; // declare the API function to check the network connection [DllImport ("wininet")] private static extern bool InternetGetConnectedState (out int connectionDescription, int reservedValue ); // check the network connection status public static bool checkNetStatus () {if (! InternetGetConnectedState (out connectionDescription, 0) {return false;} else {return true ;}// obtain the public static string getUrlSource () {string strHTML = ""; webClient myWebClient = new WebClient (); Stream myStream = myWebClient. openRead ("http://blog.csdn.net/tanghanfeng123/article/details/28867953"); // method self-designed, can be designed with parameters, so the flexibility is higher, and this address is mine, you can change your article address to StreamReader sr = new StreamReader (m YStream, System. text. encoding. getEncoding ("UTF-8"); strHTML = sr. readToEnd (); myStream. close (); return strHTML;} // check the software version. You can directly call this method as needed. Skip the preceding two methods, public static bool checkSoftVersion () {if (checkNetStatus () {Regex rg = new Regex (@ "\ d \. \ d = \ w "); // regular match, which is why I said according to certain rules to write articles, convenient match MatchCollection MS = rg. matches (getUrlSource (); foreach (Match m in MS) {// compare if (m. toString (). Equals (MianForm. softVersion + "= OK") // softVersion is the static global variable we have defined. Pay attention to modifying the variable value {// MessageBox. show ("the current software is the latest version. You can use it with confidence and use more new features! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. information); return true;} else if (m. toString (). equals (MianForm. softVersion + "= no") {MessageBox. show ("the current software is not the latest version. Please contact the author for the latest version and use more new features! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. information); return false ;}} return false;} else MessageBox. show! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. Warning); return false ;}




This is also a small piece of software I made. If you need it, you can leave a mailbox!


Small software: http://pan.baidu.com/s/1kTsSMzH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.