private void AcceptCallBack(IAsyncResult ar) { try { Client_TCP temp_client = new Client_TCP(Listener.EndAccept(ar)); Listener.BeginAccept(new AsyncCallback(AcceptCallBack), Listener); temp_client.IP = temp_client.Get_RemoteIP(); temp_client.OnServerDisconnect += Temp_client_OnServerDisconnect; temp_client.OnDropped += Temp_client_OnDropped; if (OnReceive != null) { temp_client.OnReceive += OnReceive; } Clients.Add(temp_client); if (OnAddNewClient != null) { OnAddNewClient(temp_client); } temp_client.Receive(); } catch { } }
public void seCMD(Client_TCP client, byte[] ByteArray) { string msg = ByteArrayToString(ByteArray, Encoding.UTF8); string[] temp = msg.Split(Split); switch (temp[0]) { case "Info"://刷新列表 { //string ip = ((IPEndPoint)index.socket.RemoteEndPoint).Address.ToString(); name = "无此IP数据"; string ip = client.Get_RemoteIP(); for (int i = 0; i < list.Rows.Count; i++) { if (ip == list.Rows[i][0].ToString()) { name = list.Rows[i][1].ToString(); break; } } string tep = ""; if (dataGridView2.Rows.Count != 0) { for (int i = 0; i < dataGridView2.Rows.Count; i++) { tep += Split + dataGridView2.Rows[i].Cells[0].Value.ToString() + Split + dataGridView2.Rows[i].Cells[1].Value.ToString(); } } server.Multicast(server.Clients, StringToByteArray("Come" + Split + textBox1.Text + tep + Split + name + Split + ip, Encoding.UTF8)); //Thread.Sleep(100); if (dataGridView1.Rows.Count != 0) { string info = "Info" + Split; for (int i = 0; i < dataGridView1.Rows.Count; i++) { info += dataGridView1.Rows[i].Cells[0].Value.ToString() + Split + dataGridView1.Rows[i].Cells[1].Value.ToString() + Split + dataGridView1.Rows[i].Cells[2].Value.ToString() + Split; } //client.Send(info); client.Send(StringToByteArray(info, Encoding.UTF8)); } else { // client.Send("Fail" + Split + "连接成功。"); client.Send(StringToByteArray("Mess" + Split + "连接成功。", Encoding.UTF8)); } break; } case "Roll": { string ip = client.Get_RemoteIP(); Boolean rolled = false; for (int j = 0; j < dataGridView1.Rows.Count; j++) { if (ip == dataGridView1.Rows[j].Cells[0].Value.ToString()) { rolled = true; //index.Send("Fail" + Split + "你已经Roll过点了。"); client.Send(StringToByteArray("Mess" + Split + "你已经Roll过点了。", Encoding.UTF8)); break; } } if (!rolled) { string NO = ro.Next(Int32.Parse(textBox1.Text)).ToString(); for (int i = 0; i < list.Rows.Count; i++) { if (ip == list.Rows[i][0].ToString()) { name = list.Rows[i][1].ToString(); break; } } server.Multicast(server.Clients, StringToByteArray("Roll" + Split + ip + Split + name + Split + NO, Encoding.UTF8)); //server.SendAll("Roll" + Split + ip + Split + name + Split + NO); } break; } } }