Introduction to the open-source. net Communication Framework NetworkComms framework 3 transfer List,. netnetworkcomms

Source: Internet
Author: User

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

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.