private void listBox_Member_MouseDoubleClick(object sender, MouseEventArgs e) { IPEndPoint ipe = (IPEndPoint)listBox_Member.SelectedItem; client selectitem = new client(); selectitem.Create(ipe); if (localclient.Long_ip == selectitem.Long_ip) { MessageBox.Show("您选择了与自己聊天"); return; } int index = Chatting_List.FindIndex(x => x._client.Long_ip == selectitem.Long_ip); if (index == -1) { Chatting fm2 = new Chatting(); fm2._client.Create(ipe); fm2.fm2 = new From_Chatting(); fm2.fm2.Text = ipe.ToString(); fm2.fm2.ChatWho = ipe; fm2.fm2.Fromclose = new ChildFromClose(Chat_Close); fm2.fm2.Show(); Chatting_List.Add(fm2); } }
public void ChatControl(byte[] pack, IPEndPoint ip_come) { CheckAlive(ip_come); client tem = new client(); tem.Create(ip_come); // 搜索已经开启聊天的表 int index = Chatting_List.FindIndex(x => x._client.Long_ip == tem.Long_ip); if (index == -1) // 新用户 { Chatting fm2 = new Chatting(); fm2._client.Create(ip_come); fm2.fm2 = new From_Chatting(); fm2.fm2.Text = ip_come.ToString(); fm2.fm2.ChatWho = ip_come; fm2.fm2.Fromclose = new ChildFromClose(Chat_Close); fm2.fm2.Show(); Chatting_List.Add(fm2); ShowMessageService sms = new ShowMessageService(fm2.fm2.UpdateLabel); byte[] str = pack.Skip(1).ToArray(); this.BeginInvoke(sms, Encoding.Default.GetString(str)); } else { ShowMessageService sms = new ShowMessageService(Chatting_List[index].fm2.UpdateLabel); byte[] str = pack.Skip(1).ToArray(); this.BeginInvoke(sms, Encoding.Default.GetString(str)); } }
private void Chat_Close(IPEndPoint ip_close)// 自窗口关闭后续处理 { client client_close = new client(); client_close.Create(ip_close); int index = Chatting_List.FindIndex(x => x._client.Long_ip == client_close.Long_ip); Chatting_List.RemoveAt(index); }
private void Error_Result(bool status, IPEndPoint iep) { client cl = new client(); cl.Create(iep); int index = MemberTable.Tables.FindIndex(x => x.Long_ip == cl.Long_ip); if (index >= 0) { MemberTable.Tables[index].hash_result = status; } }
public bool Add(client cl)// 添加成员 { if (Tables.Contains(cl)) { return(false); } client cli = new client(); cli.Create(cl.IP_PORT); Tables.Add(cli); Update(); return(true); }
private void CheckAlive(IPEndPoint ip_come) { client cl = new client(); cl.Create(ip_come); if (MemberTable.Contains(cl)) { int index = MemberTable.Tables.FindIndex(x => x.Long_ip == cl.Long_ip); MemberTable.Tables[index].boAlive = true; return; } cl.boAlive = true; MemberTable.Add(cl); TableToDis(); }
private void Form1_Load(object sender, EventArgs e) { localUdpclient = new UdpClient(localAddress); Thread reth = new Thread(new ThreadStart(RecvTh)); reth.IsBackground = true; reth.Start(); net_even += new NetEvenCall(NetEven); //取得本地使用的接口信息 localclient.Create((IPEndPoint)localUdpclient.Client.LocalEndPoint); //将自己加入Table localclient.hash_result = true; MemberTable.Add(localclient); TableToDis(); disupdate = new UpdateListDis(UpdateDis); textBox_IP.Text = "127.0.0.1"; timer1.Start(); label1.Text = localclient.IP_PORT.ToString(); }