private void UpdateTheFriendList() { List <Object> listInfo = new List <object>(); listInfo.Add("7"); //代表是更新用户列表 listInfo.Add(Ip); listInfo.Add(Port); TcpSkt tcpskt = new TcpSkt(); List <Object> listInfo2 = tcpskt.LR_ActionSend_Receive(listInfo); if (listInfo2 == null) { MessageBox.Show("连接服务器失败,可能是服务端未开启,请联系管理员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (listInfo2[0].ToString() == "7") //相等时候更新成功 { //从服务器取得信息 到客户端 (其他客户端信息) 传给主界面 listView1.Invoke((MethodInvoker)(() => //更新服务器的显示信息 { listInfo2.Add(Ip); listInfo2.Add(Port); listView1.Items.Clear(); FullListViewAndShowInfo(listView1, listInfo2); })); } else { MessageBox.Show("更新失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//代表是获取用户信息 void GetUserInfo2() { List <Object> listInfo = new List <object>(); listInfo.Add("22"); //代表是获取用户信息 listInfo.Add(IpDetail); listInfo.Add(PortDetail); TcpSkt tcpskt = new TcpSkt(); List <Object> listInfo2 = tcpskt.LR_ActionSend_Receive(listInfo); if (listInfo2 == null) { MessageBox.Show("连接服务器失败,可能是服务端未开启,请联系管理员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (listInfo2[0].ToString() == "22") //相等时候获取成功 { //从服务器取得user信息 到客户端 (其他客户端信息) 传给主界面 UserInfo = new List <object>(); for (int s = 1; s < 9; s++) { UserInfo.Add(listInfo2[s].ToString()); } } else { MessageBox.Show("更新失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void loginIp_Click(object sender, EventArgs e) { if (CheckInputRule() == false) { return; } List <Object> listInfo = new List <object>(); listInfo.Add("3"); //代表是登陆中&请求登陆 listInfo.Add(this.textBox1.Text); listInfo.Add(this.textBox2.Text); listInfo.Add(this.textBox3.Text); TcpSkt tcpskt = new TcpSkt(); List <Object> listInfo2 = tcpskt.LR_ActionSend_Receive(listInfo); if (listInfo2 == null) { MessageBox.Show("连接服务器失败,可能是服务端未开启,请联系管理员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (listInfo2[0].ToString() == "4") //相等时候登陆成功 { //从服务器取得信息 到客户端 (其他客户端信息) 传给主界面 listInfo2.Add(this.textBox1.Text); //自己的ip listInfo2.Add(this.textBox2.Text); //自己的port this.Owner.Tag = listInfo2; this.Close(); } else { MessageBox.Show("登陆失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Owner.Close(); } }
void button1_Click(object sender, EventArgs e) { if (CheckInputRule() == false) { return; } List <Object> listInfo = new List <object> (); listInfo.Add("1"); //代表是注册 listInfo.Add(this.textBox1.Text); listInfo.Add(this.textBox2.Text); listInfo.Add(this.textBox3.Text); listInfo.Add(this.textBox4.Text); listInfo.Add(GetSex()); TcpSkt tcpskt = new TcpSkt(); List <Object> listInfo2 = tcpskt.LR_ActionSend_Receive(listInfo); //发送注册信息给服务端 if (listInfo2 == null) { MessageBox.Show("连接服务器失败,可能是服务端未开启,请联系管理员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (listInfo2[0].ToString() == "2") { MessageBox.Show("注册成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (listInfo2[0].ToString() == "23") { MessageBox.Show("(23)用户已存在\n请用其他的ip port注册!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//关闭时 让服务器改变登陆状态 void ClientForm_FormClosed(object sender, FormClosedEventArgs e) { //让服务器改变登陆状态 List <Object> listInfo = new List <object>(); listInfo.Add("12"); //代表 客户端下线 listInfo.Add(Ip); listInfo.Add(Port); if (Ip == null) //判断是否是在进入主窗体后退出 Ip==null 则是在登陆前gg { return; } TcpSkt tcpskt = new TcpSkt(); List <Object> listInfo2 = tcpskt.LR_ActionSend_Receive(listInfo); if (listInfo2 == null) { MessageBox.Show("连接服务器失败,可能是服务端未开启,请联系管理员", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (listInfo2[0].ToString() == "12") //相等时候退出成功 { MessageBox.Show("已退出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("退出出现错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Owner.Close(); } }