"Source" C # written by the Android client and Windows Server program for network communication

Source: Internet
Author: User

Developing the Android Program (xamarin.android) series three in C #

Source (contains client and server-side all project files) database file

In order to facilitate your testing, I temporarily set up a server you can install the APK file, directly test the APK file (the test server will run until March 1, 2015)

Communication framework for NetworkComms2.3.1 Open source communication framework serialized from UK using protobuf.net open source framework

The client interface is as follows:

Server-Side Program interface:

The server is built on winserver2003, based on. net4.0.

Database with sql2005

Input data:

Database construction complete, open VS2010 Start, create related projects

Create a server-side project

Next: Open codesmith create "stored procedure", "Data Layer" code, "logical layer (business layer code)":

Related Codesmith templates:

share the database framework I'm using

The Codesmith used is version 6.5:

When the build is complete, vs in the drawing:

Next, build the server code first

Adding stored procedures to the database

Added in DBUsers.CS:

        //add a user based on UserID         Public StaticIDataReader Getonebyusername (stringname) {Sqlparameterhelper SPH=NewSqlparameterhelper (Getreadconnectionstring (),"Users_selectonebyusername",1); Sph. Definesqlparameter ("@Name", SqlDbType.NVarChar, $, ParameterDirection.Input, name); returnSPH.        ExecuteReader (); }

Add the logical layer Dousers:

   Public Static stringLogin (stringUsernamestringpassword) {             using(IDataReader reader =Dbusers.getonebyusername (username)) {                stringTheresult ="Login not successful"; Users Theuser=Populatefromreader (reader); if(Theuser = =NULL) {Theresult="user does not exist"; }                Else if(Theuser.password = =password) {Theresult="Landing Success"; }                Else{Theresult="The password is not correct"; }                returnTheresult; }        }

Server-side code:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingnetworkcommsdotnet;usingSystem.Net;usingmobile.business;usingmobile.entity;namespacemobileserver{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidButton1_Click (Objectsender, EventArgs e) {             //server starts listening for client requests//start listening on a T portIPEndPoint Thepoint =NewIPEndPoint (Ipaddress.parse (Txtip.text),int.            Parse (Txtport.text)); Tcpconnection.startlistening (Thepoint,false); Button1. Text="Listening in"; Button1. Enabled=false; //This method contains server-specific processing methods. startlistening (); }        Private voidstartlistening () {//Disable logging when the server side of logging is disabled for official usenetworkcomms.disablelogging (); //Handling Login RequestsNetworkcomms.appendglobalincomingpackethandler<users> ("Userlogin", incomingloginrequest); }        //to process a specific request        Private voidincomingloginrequest (packetheader header, Connection Connection, Users currentUser) {Try            {                //get the returned results from the database                stringResmsg =Dousers.login (Currentuser.name,currentuser.password); Resmessage Contract=NewResmessage (); Contract. Message=resmsg; //return the results to the clientConnection. SendObject ("Reslogin", contract); }            Catch(Exception ex) {}}Private voidForm1_formclosing (Objectsender, 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.

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.


To modify the Main.axml file, add a few text boxes to the user to enter the user name and password:

Modify the Main.axml filemainactivity Code

The article first wrote here, I hope you like

www.networkcomms.cn Edit

"Source" C # written by the Android client and Windows Server program for network communication

Related Article

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.