标签:
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(); this.Dispose(); this.Close(); } } www.networkcomms.cn编辑
标签:
原文地址:http://www.cnblogs.com/networkcomms/p/4257045.html