Source Code (contains client and server-side all project files) Database Files
to facilitate the test, I temporarily set up a server can install the APK file, directly test apk file
Communication framework for NetworkComms2.3.1 Open source communication framework serialized from UK using protobuf.net open source framework
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221726126116766.jpg "width=" 289 "height= "514" style= "border:0px;"/> 650) this.width=650; "Src=" http://images.cnitblog.com/blog/586310/201502/221726298615296.jpg " Width= "287" height= "510" style= "border:0px;"/>
Server-Side Program interface:
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221751026114230.jpg "style=" border:0px; " />
The server is built on winserver2003, based on. net4.0.
Database with sql2005
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221018536897834.jpg "style=" border:0px; " />
Input data:
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221710524553978.jpg "style=" border:0px; " />
Database construction complete, open VS2010 Start, create related projects
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221021453616021.jpg "style=" border:0px; " />
Create a server-side project
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221025467528240.jpg "style=" border:0px; " />
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221456144711015.jpg "style=" border:0px; " />
Next: Open codesmith create "stored procedure", "Data Layer" code, "logical layer (business layer code)":
Related Codesmith templates:
The Codesmith used is version 6.5:
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221046117994316.jpg "style=" border:0px; " />
When the build is complete, vs in the drawing:
650) this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221457208469836.jpg "style=" border:0px; " />
Next, build the server code first
650) this.width=650; "id=" Code_img_closed_5dfb393a-0992-45bf-b7a4-b977fd283f42 "class=" code_img_closed "src=" http ://images.cnblogs.com/outliningindicators/contractedblock.gif "style=" border:0px;vertical-align:middle; padding-right:5px; add a stored procedure in the/> Database
dbusers.cs added:
Add based on UserID get user public static IDataReader getonebyusername (string name) {Sqlparamet Erhelper SPH = new Sqlparameterhelper (getreadconnectionstring (), "Users_selectonebyusername", 1); Sph. Definesqlparameter ("@Name", SqlDbType.NVarChar, $, parameterdirection.input, Name); Return SPH. ExecuteReader (); }
Public static string login (String username, string password) { using (Idatareader reader = dbusers.getonebyusername (username)) { string theResult = "Login Unsuccessful"; Users theUser = Populatefromreader (reader); if (theuser == null) { theresult = "User does not exist"; } else if (Theuser.password == password) { theResult = " Login Successful "; } else { theresult = " The password is incorrect "; } return theresult; } }
Server-side code:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using System.Windows.Forms;
Using Networkcommsdotnet;
Using system.net;using mobile.business;using mobile.entity;namespace mobileserver
{Public partial class Form1:form
{Public Form1 ()
{
InitializeComponent ();
private void Button1_Click (object sender, EventArgs e)
{
Server starts listening for client requests
Start listening on a T port
IPEndPoint thepoint = new IPEndPoint (Ipaddress.parse (txtip.text), Int. Parse (Txtport.text));
Tcpconnection.startlistening (Thepoint, false);
Button1. Text = "in-listen";
Button1. Enabled = false; This method contains server-specific processing methods. Startlistening ();
} private void Startlistening ()
{
Disable logging when the server-side is officially used, disable log logging networkcomms.disablelogging ();
Handling Login Requests
Networkcomms.appendglobalincomingpackethandler<users> ("Userlogin", incomingloginrequest);
}//handling a specific request
private void Incomingloginrequest (Packetheader header, Connection Connection, Users currentUser)
{Try
{//Get returned results from the database
String resmsg = Dousers.login (Currentuser.name,currentuser.password);
Resmessage contract = new Resmessage ();
Contract. Message = resmsg; Return the results to the client
Connection. SendObject ("Reslogin", contract);
} catch (Exception ex)
{
}
private void Form1_formclosing (object sender, FormClosingEventArgs e)
{
Networkcomms.shutdown (); This. Dispose (); This. Close ();
}
}
}
At this point, we have completed the "Construction database", "Build Table", "Generate database stored procedure", "Data layer Code", "Logical Layer Code", "Writing server-side code". Only the Android client was written.
Another point is the encryption protection of the Android client, here to share the recommended encryption technology I used-- Encryption technology for Love encryption Android app , is definitely a professional Android application encryption protection platform!
With the Xamarin platform, the biggest advantage of developing Android programs in the C # language is that you can use the many excellent library classes on the. NET platform, especially through a stable and mature communication framework to interact with the C # server side.
650) this.width=650; "src=" Http://images.cnitblog.com/blog/586310/201502/221450443617332.jpg "style=" border:0px; "/>650" this.width=650; "src=" http://images.cnitblog.com/blog/586310/201502/221139051114685.jpg " Style= "border:0px;width:1060px;"/>
To modify the Main.axml file, add a few text boxes to the user to enter the user name and password:
650) this.width=650; "id=" code_img_closed_184583bd-6934-4233-b892-75b211deb652 "class=" code_img_closed "src=" http ://images.cnblogs.com/outliningindicators/contractedblock.gif "style=" border:0px;vertical-align:middle; padding-right:5px; "/> Modify the Main.axml file
650) this.width=650; "id=" CODE_IMG_CLOSED_B7AA1462-B206-426A-A841-2535648CC4DC "class=" code_img_closed "src=" http ://images.cnblogs.com/outliningindicators/contractedblock.gif "style=" border:0px;vertical-align:middle; padding-right:5px; "/> mainactivity code
"Source" C # written by the Android client and Windows Server program for network communication