Original URL: Http://www.cnblogs.com/csdev
Networkcomms is a C # language written by TCP/UDP communication framework The author is the British used to charge the current author has open source address is: Https://github.com/MarcFletcher/NetworkComms.Net
This section tells you how to get list data from the server
Example diagram:
Customer single click Get Data return data from server
Client code:
Private voidButton4_Click (Objectsender, EventArgs e) { //Getuserlist is the request message type of the data//Resuserlist is the server-side return message type when the server returns resuserlist data when the client automatically corresponds to getilist<user> Listuser = newtcpconnection.sendreceiveobject<string, Ilist<user>> ("getuserlist","resuserlist", the," -"); Binddata (Listuser); } Public voidBinddata (ilist<user>theusers) {listView1.Items.Clear (); ListView1.Columns.Clear (); Listview1.view= View.Details;//New Detailed waysListview1.allowcolumnreorder =true; Listview1.fullrowselect=true; Listview1.gridlines=true; LISTVIEW1.COLUMNS.ADD ("User ID", -, HorizontalAlignment.Left); LISTVIEW1.COLUMNS.ADD ("User name", -, HorizontalAlignment.Left); foreach(User theuserinchtheusers) {ListViewItem Li=NewListViewItem (); Li. subitems[0]. Text =theUser.UserID.ToString (); Li. SubItems.Add (Theuser.name); ListView1.Items.Add (LI); } }
Server-side code:
Private voidButton1_Click (Objectsender, EventArgs e) { //IP address and portIPEndPoint Thepoint =NewIPEndPoint (Ipaddress.parse (Txtip.text),int. Parse (Txtport.text)); //start listening for this IP and port using the TCP protocolconnection.startlistening (connectiontype.tcp, thepoint); Networkcomms.appendglobalincomingpackethandler<string> ("GetName", Incomingmsghandle); Networkcomms.appendglobalincomingpackethandler<User> ("Userlong", Incoinghandlelogin); Networkcomms.appendglobalincomingpackethandler<string> ("getuserlist", incoinghandlegetuserlist); Button1. Text="already started listening ."; }
Private voidIncoinghandlegetuserlist (packetheader header, Connection Connection,stringparam) { //simulate some dataIlist<user> userlist=NewList<user>(); User User1=NewUser (); User1. UserID="10000"; User1. Name="Tianya at this time"; User User2=NewUser (); User2. UserID="20000"; User2. Name="The Moon shines on the sea"; if(param = =" -") {userlist.add (user1); Userlist.add (User2); } Else{userlist.add (user1); } connection. SendObject ("resuserlist", userlist); }
SOURCE Download: Http://pan.baidu.com/s/1geXMSef
Introduction to the Open source. NET Communication Framework NETWORKCOMMS framework three pass list