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) { //给契约类赋值 LoginContract contract = new LoginContract(); contract.UserID = txtUserName.Text; contract.PassWord = txtPassword.Text; //向服务器发送登录信息并获取登录结果 ResMsgContract resMsg = newTcpConnection.SendReceiveObject<ResMsgContract>("ReqLogin", "ResLogin", 5000, contract); if (resMsg.Message == "登录成功") { MessageBox.Show("登录成功"); } else { MessageBox.Show("用户名密码错误"); } } //http://shop115882994.taobao.com private void Form1_FormClosing(object sender, FormClosingEventArgs e) { NetworkComms.Shutdown(); this.Dispose(); this.Close(); } } www.networkcomms.cn编辑http://www.cnblogs.com/networkcomms
时间: 2024-10-27 07:14:21