private void button8_Click(object sender, EventArgs e) { if (this.send_result_listView.Items.Count == 0) { MessageBox.Show("发送地址为空!"); return; } foreach (ListViewItem item in this.send_result_listView.Items) { this.send_result_listView.BeginUpdate(); IpAddr ip = new IpAddr(); ip.IpAddrs = item.Text; ip.Port = item.SubItems[1].Text; SocketUtil sktutil = new SocketUtil(); Socket clientSocket = sktutil.getConnection(ip.IpAddrs, ip.Port); if (clientSocket != null) { bool success = sktutil.sendMessage(clientSocket, this.message); if (success) { string response = sktutil.receiveMessage(clientSocket); //MessageBox.Show(response); item.SubItems.Add("回应:" + response); } else { item.SubItems.Add("失败"); } sktutil.disConnection(clientSocket); } else { item.SubItems.Add("无法连接"); } this.send_result_listView.EndUpdate(); } }