Introduction to the open-source. net Communication Framework NetworkComms framework 3 transfer List,. netnetworkcomms
Http://www.cnblogs.com/csdev
Networkcomms is a C # language written TCP/UDP Communication Framework author is British previously is charged by the current author has open source address: https://github.com/MarcFletcher/NetworkComms.Net
This section describes how to obtain list data from the server.
Example:
The customer clicks to retrieve data and returns data from the server
Client code:
Private void button4_Click (object sender, EventArgs e) {// GetUserList is the data request message type. // ResUserList is the server-side message type. When the server returns ResUserList data, the client automatically obtains the IList <User> listUser = newTcpConnection. sendReceiveObject <string, IList <User> ("GetUserList", "ResUserList", 5000, "100"); BindData (listUser );} public void BindData (IList <User> theUsers) {listView1.Items. clear (); listView1.Columns. clear (); listView1.View = View. details; // added Details: listView1.AllowColumnReorder = true; listView1.FullRowSelect = true; listView1.GridLines = true; listView1.Columns. add ("User ID", 100, HorizontalAlignment. left); listView1.Columns. add ("the user name", 100, HorizontalAlignment. left); foreach (User theUser in theUsers) {ListViewItem li = new ListViewItem (); li. subItems [0]. text = theUser. userID. toString (); li. subItems. add (theUser. name); listView1.Items. add (li );}}
Server code:
Private void button#click (object sender, EventArgs e) {// IP address and port IPEndPoint thePoint = new IPEndPoint (IPAddress. parse (txtIP. text), int. parse (txtPort. text); // start listening for this IP address and port using TCP Connection. startListening (ConnectionType. TCP, thePoint); NetworkComms. appendGlobalIncomingPacketHandler <string> ("GetName", IncomingMsgHandle); NetworkComms. appendGlobalIncomingPacketHandler <User> ("UserLong", IncoingHandleLogin); NetworkComms. appendGlobalIncomingPacketHandler <string> ("GetUserList", IncoingHandleGetUserList); button1.Text = "listener started ";}
Private void IncoingHandleGetUserList (PacketHeader header, Connection connection, string param) {// simulate some data IList <User> userList = new List <User> (); user user1 = new User (); user1.UserID = "10000"; user1.Name = ""; User user2 = new User (); user2.UserID = "20000 "; user2.Name = ""; if (param = "100") {userList. add (user1); userList. add (user2);} else {userList. add (user1);} connection. sendObject ("ResUserList", userList );}
Source code download: http://pan.baidu.com/s/1geXMSef