Yi Meng tcp file upload download and Automatic Update system introduction (TCP File Transfer)
The system is based on the open source Networkcomms communication framework, which was previously charged, is now free and Kaiyuan, the author is the United Kingdom, the development time of more than 5 years, the framework is very stable.
Project Address: Http://www.51aspx.com/code/MSDCArtMengFileUpload
Consulting qq:286275658
Demo Program: HTTP://PAN.BAIDU.COM/S/1GEVFMCR
The principle of automatic upgrade:
(1) After the client is logged in, determine the version number in the local configuration file and the server version number, if it is smaller than the server version number, close this program, start the upgrade program
//Start the upgrade program Private voidAppupdate () {
Contact Server Request Server version number Upgradeconfig UPGRADECONIFG= appoutter.tcpconn.sendreceiveobject<string, Upgradeconfig> ("getupmsg","resupmsg", the,"Test");
If the server has a large version number, start the upgrade programif(Upgradeconifg.appversion >getmenuversion ()) {
To get the name of the upgrade program from the configuration file, start the programstringUpgradeapppath = system.configuration.configurationmanager.appsettings["Upgradeapp"]; stringCallBack = AppDomain.CurrentDomain.BaseDirectory +Upgradeapppath; if(File.exists (callBack)) {if(Properties.Settings.Default.IpAddress = = system.configuration.configurationmanager.appsettings["IPAddress"]) {System.Diagnostics.Process Process=System.Diagnostics.Process.Start (CallBack); } Else{System.Diagnostics.Process Process= System.Diagnostics.Process.Start (CallBack,"s"); } } Else{MessageBox.Show ("Target program does not exist"+callBack); } System.Environment.Exit (0); } }
Configuration file for the upgrade program:
Exeappname is the main program name that is configured to restart the main program after the upgrade is completed and after you close itself.
Part of the code:
Private voidstartupdate () {//Set get file information class priority HighUpgradeconfig UPGRADECONIFG = connection. sendreceiveobject<string, Upgradeconfig> ("getupmsg","resupmsg", the,"Test", Customoptions, customoptions); if(Upgradeconifg.appversion >0) {Listbox1.datasource=upgradeconifg.filelist; TextBox1.Text=upgradeConifg.AppVersion.ToString (); //The number of files that need to be downloadedUpfilescount =UpgradeConifg.FileList.Count; //Send message request download upgrade file stringFilePath =AppDomain.CurrentDomain.BaseDirectory; //sends the local file's storage path to the server side (which is then brought back by the server-side Sendinfo)Connection. sendobject<string> ("Getupfile", FilePath, customoptions); } Else{MessageBox.Show ("No upgrade required"); } }
View Code
After getting the list of files for this upgrade from the server, download the files from the server to local.
After the upgrade is complete, close the program, start the main program, complete the upgrade.
Yi Meng tcp file transfer and Automatic Update system introduction (TCP File Transfer) (ii)