Demo1.从服务器获取信息 客户端代码

NetworkComms网络通信框架序言

public partial class Form1 : Form { //连接信息类 public ConnectionInfo connInfo = null; //连接类 Connection newTcpConnection; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { connInfo = new ConnectionInfo(txtIP.Text, int.Parse(txtPort.Text)); //如果不成功,会弹出异常信息 newTcpConnection = TCPConnection.GetConnection(connInfo); button1.Enabled = false; button1.Text = "连接成功"; } private void button2_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex > -1) { //这里的“ReqFruitEngName","ResFruitEngName"分别代表请求类型和返回类型 //这个类型的名称随便起,只要和服务器端代码对应上即可 //请求名称设定为 ReqFruitEngName,然后在服务器代码中就针对这个请求类型进行数据处理,并返回 ResFruitEngName类型的消息 string resMsg = newTcpConnection.SendReceiveObject<string>("ReqFruitEngName", "ResFruitEngName", 5000, listBox1.Text); MessageBox.Show("您选择的水果的英文名称是:" + resMsg); } else { MessageBox.Show("请选择一项"); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { NetworkComms.Shutdown(); Environment.Exit(Environment.ExitCode); } } www.networkcomms.cn编辑

 

你可能感兴趣的:(demo)